Index: trunk/code/behaviors/hunter_prey/james/main.c
===================================================================
--- trunk/code/behaviors/hunter_prey/james/main.c	(revision 1847)
+++ trunk/code/behaviors/hunter_prey/james/main.c	(revision 1848)
@@ -1,13 +1,9 @@
+/*HUNTER_PREY by jamesCarroll 10/26/10*/
 #include <dragonfly_lib.h>
 #include <wl_basic.h>
 #include "hunter_prey.h"
 
-#define WL_CHANNEL 15
-#define HUNTER 3
-#define PREY 1
-#define PREHUNTER 2
-#define PREPREY 0
-#define WAITING 4
+#define WL_CHANNEL 15 
 
 /* Variables used to receive packets */
 unsigned char* packet_data;
@@ -14,193 +10,155 @@
 int data_length;
 
 /*  Data buffer used to send packets */
-char send_buffer[2];
+char send_buffer[3];
 
 int main(void)
 {
 
-	/* Initialize dragonfly board */
-	dragonfly_init(ALL_ON);
-	/* Initialize the XBEE */
-	xbee_init();
-	/* Initialize the basic wireless library */
-	wl_basic_init_default();
-	/* Set the XBee channel to your assigned channel */
-	wl_set_channel(WL_CHANNEL);
-	/* Initialize Orbs*/
-	orb_init();
-	/* Initialize Clock*/
-	rtc_init(SIXTEENTH_SECOND, NULL);
-	/* Initialize motors*/
-	motors_init();
+    /* Initialize dragonfly board */
+    dragonfly_init(ALL_ON);
+    /* Initialize the basic wireless library */
+    wl_basic_init_default();
+    /* Set the XBee channel to your assigned channel */
+    wl_set_channel(WL_CHANNEL);
 
-	int state=PREPREY, time, max_bom_reading, front_rangefinder_reading, angle, d1=80, d2=80, d3=80, d4=80, d5=80, speed=0;
-	unsigned char id=get_robotid(), tag;
+    /* ****** CODE HERE ******* */
+	int yes= 1;
+	int no = 3;
+	int speed = 200;
+	int isHunter = yes;
+	int t1 = 0;
+	int t2 = 0;
+	int timechecked = 0;
+	int beginning = 1;
+	send_buffer[2] = get_robotid();
+	if(wheel()<100)
+		isHunter=yes;
+	else
+		isHunter=no;
 
-	if(wheel() < 100)
-		state=HUNTER;
-
-	while(1){
-		switch(state)
+	while(1)
+	{
+		if(isHunter == yes)
 		{
-			case PREPREY:
+			bom_off();
+			orb_set_color(RED);
+			while(1)
+			{
+				int front = 0;
+				front = range_read_distance(IR2);
+				bom_refresh(BOM_ALL);
+				int bomNum = 0;
+				bomNum = bom_get_max();
+				if(hunter_prey_tagged(bomNum, front))
 				{
-					orb1_set_color(YELLOW);
-					bom_on();
-					state=PREY;
-					motor_r_set(BACKWARD,200);
-					motor_l_set(BACKWARD,200);
-					delay_ms(2000);
-					while(wl_basic_do_default(&data_length));
-					orb1_set_color(GREEN);
-					rtc_reset();
-					break;
+					send_buffer[0] = HUNTER_PREY_ACTION_TAG;
+					send_buffer[1] = get_robotid();
+					wl_basic_send_global_packet(42, send_buffer, 3);
 				}
-			case PREY:
+				packet_data = wl_basic_do_default(&data_length);
+				if(packet_data != 0)
 				{
-					int t1 = 0;
-					int t2 = 0;
-					int timechecked = 0;
-					int beginning = 1;
-					orb1_set_color(GREEN);
-					orb2_set_color(GREEN);
-
-					while(1)
+					if(data_length == 3 && packet_data[0] == HUNTER_PREY_ACTION_ACK)
 					{
-						int front = range_read_distance(IR2);
-						packet_data = wl_basic_do_default(&data_length);
-						if(packet_data != 0)
+						if(packet_data[1] == get_robotid())
 						{
-							if(data_length == 2 && packet_data[0] == HUNTER_PREY_ACTION_TAG)
-							{
-								send_buffer[0] = HUNTER_PREY_ACTION_ACK;
-								send_buffer[1] = packet_data[1];
-								wl_basic_send_global_packet(42, send_buffer, 2);
-								state=PREHUNTER;
-								motor_r_set(0,0);motor_l_set(0,0);
-								break;
-							}
+							orb_set_color(GREEN);
+							isHunter = no;
+							motor_l_set(1, 200);
+							motor_r_set(0,200);delay_ms(1000);break;
 						}
-						int side1 = range_read_distance(IR1);
-						int side2 = range_read_distance(IR3);
-						t2 = rtc_get();
-						if(front < 200 && front > 50 && !(timechecked == 1))
-						{
-							orb2_set_color(RED);
-							timechecked = 1;
-							t1 = rtc_get();
-							motor_l_set(1, 255);
-							motor_r_set(0, 0);
+						else{
+							orb_set_color(BLUE);motor_r_set(0,0);motor_l_set(0,0);delay_ms(3000);break;
 						}
-						else if(side1 < 300 && side1 > 0 && timechecked != 1)
-						{
-							motor_r_set(0,0);
-						}
-						else if(side2 < 300 && side2 > 0 && timechecked != 1)
-						{
-							motor_l_set(0,0);
-						}
-						else
-						{
-							if(t2 - t1 > 2 || beginning == 1)
-							{
-								orb2_set_color(BLUE);
-								timechecked = 0;
-								motor_l_set(1, 255);
-								motor_r_set(1, 255);
-								beginning = 0;
-							}
-						}
 					}
-					break;
 				}
-			case PREHUNTER: /*new hunter mode (5 second pause)*/
-				{
-					orb1_set_color(BLUE);
-					orb2_set_color(BLUE);
-					motors_off();
-					state=HUNTER;
-					rtc_reset();
-					bom_off();
-					delay_ms(3000);		
-					while(wl_basic_do_default(&data_length));
-					orb1_set_color(RED);
-					break;
+				bom_refresh(BOM_ALL);
+				bomNum = bom_get_max();
+				if(bomNum == 4)
+				{	
+					motor_l_set(1, speed);
+					motor_r_set(1, speed);
 				}
-			case HUNTER:
+				else
 				{
-					orb1_set_color(RED);
-					orb2_set_color(RED);
-					/*HUNT*/
-					angle=0; speed=FULL_SPD;
-					if(max_bom_reading==4){
-						motor_l_set(FORWARD, 255);
-						motor_r_set(FORWARD, 255);
+					if(bomNum == -1){}
+					else if((bomNum >= 12) || (bomNum < 4))
+					{
+						motor_l_set(FORWARD, speed);
+						motor_r_set(BACKWARD, speed);
 					}
-					if(max_bom_reading>=1 && max_bom_reading<=3){
-						motor_l_set(FORWARD, 255);
-						motor_r_set(FORWARD, 190);
+					else
+					{
+						motor_l_set(BACKWARD, speed);
+						motor_r_set(FORWARD, speed);
 					}
-					if(max_bom_reading>=5 && max_bom_reading<=7){
-						motor_l_set(FORWARD, 190);
-						motor_r_set(FORWARD, 255);
+				}
+			}
+		}
+		else
+		{
+			orb_set_color(GREEN);
+			bom_on();
+			while(1)
+			{
+				int front = range_read_distance(IR2);
+				packet_data = wl_basic_do_default(&data_length);
+				if(packet_data != 0)
+				{	
+					if(data_length == 3 && packet_data[0] == HUNTER_PREY_ACTION_TAG)
+					{
+						send_buffer[0] = HUNTER_PREY_ACTION_ACK;
+						send_buffer[1] = packet_data[1];
+						wl_basic_send_global_packet(42, send_buffer, 3);
+						isHunter=yes;
+						orb_set_color(BLUE);
+						motor_r_set(0,0);motor_l_set(0,0);
+						bom_off();
+						delay_ms(3000);
+						break;
 					}
-					if((max_bom_reading>=8 && max_bom_reading<=11) || max_bom_reading<0){
-						motor_l_set(BACKWARD, 170);
-						motor_r_set(FORWARD, 255);
-						orb2_set_color(RED);
-					}
-					if((max_bom_reading>=12 && max_bom_reading<=15) || max_bom_reading==0){
-						motor_l_set(FORWARD, 255);
-						motor_r_set(BACKWARD, 170);
-					}
-					/*Tagging*/
-					packet_data = wl_basic_do_default(&data_length);
-					if(packet_data != 0 && packet_data[0]==HUNTER_PREY_ACTION_ACK && packet_data[1]!=id){
-						state=PREHUNTER;
-					}
-					bom_refresh(BOM_ALL);  
-					front_rangefinder_reading = -1;
-					while(front_rangefinder_reading == -1){
-						front_rangefinder_reading = range_read_distance(IR2);
-					}
-					delay_ms(10);
-					max_bom_reading = bom_get_max();
-					tag = hunter_prey_tagged(max_bom_reading, front_rangefinder_reading);  
-					time = rtc_get();
-					if(button2_read()==1 || (tag && time>16)){
-						send_buffer[0]=HUNTER_PREY_ACTION_TAG;
-						send_buffer[1]=id;
-						wl_basic_send_global_packet( 42, send_buffer, 2 );
-						rtc_reset();
-						state=WAITING;
-						orb1_set_color(PURPLE);
-					}
-					break;
 				}
-			case WAITING: /*Waiting for ack after sending tag*/
+				int side1 = range_read_distance(IR1);
+				int side2 = range_read_distance(IR3);
+				t2 = rtc_get();
+				if(front < 200 && front > 50 && !(timechecked == 1))
 				{
-					time = rtc_get();
-					packet_data = wl_basic_do_default(&data_length);
-					if(packet_data != 0 && packet_data[0]==HUNTER_PREY_ACTION_ACK && packet_data[1]==id){
-						state=PREPREY;
-						rtc_reset();
+					orb2_set_color(RED);
+					timechecked = 1;
+					t1 = rtc_get();
+					motor_l_set(1, speed);
+					motor_r_set(0, 0);
+				}
+				else if(side1 < 300 && side1 > 0 && timechecked != 1)
+				{
+					motor_r_set(0,0);
+				}
+				else if(side2 < 300 && side2 > 0 && timechecked != 1)
+				{
+					motor_l_set(0,0);
+				}
+				else
+				{
+					if(t2 - t1 > 2 || beginning == 1)
+					{
+						orb2_set_color(BLUE);
+						timechecked = 0;
+						motor_l_set(1, speed);
+						motor_r_set(1, speed);
+						beginning = 0;
 					}
-					if(packet_data != 0 && packet_data[0]==HUNTER_PREY_ACTION_ACK && packet_data[1]!=id){
-						state=PREHUNTER;
-					}
-					if(time>16){
-						state=HUNTER;
-						orb1_set_color(RED);
-					}
-					break;
 				}
+			}
 		}
 	}
 
-	while(1);
 
-	return 0;
+    /* ****** END HERE ******* */
 
+    while(1);
+
+    return 0;
+
 }
 
