Project

General

Profile

Revision 1467

ref seems to work if everyone behaves

View differences:

main.c
7 7
#include "../hunter_prey.h"
8 8

  
9 9
#define TYPE 42	// packet type for wireless communication
10
#define ROBOTID 255 // make up a robot id because the PC doesn't have one
11 10

  
11
#define NUM_BOTS 17
12
#define TOTAL_GAME_TIME 600*5 //in 100 ms intervals
13

  
12 14
void packet_receive(char type, int source, unsigned char* packet, int length);
13 15

  
14 16
volatile unsigned int preyTime[20];
......
30 32

  
31 33
  int i=0;
32 34

  
33
  for(i=0;i<20;i++) {
35
  for(i=0;i<NUM_BOTS;i++) {
34 36
    printf("%5d ", preyTime[i]);
35 37
  }
36 38

  
......
45 47
    unsigned char *packet_data;	// data received
46 48
    int ret;
47 49
    int i;
50
    int winner, maxTime=0;
48 51

  
49 52
    unsigned int channel = 0xF;
50 53

  
......
70 73
    }
71 74
    //wl_set_channel(channel);
72 75

  
73
    for(i=0;i<16;i++) {
76
    for(i=0;i<NUM_BOTS;i++) {
74 77
      preyTime[i]=0;
75 78
    }
76 79

  
......
80 83
    printf("ready\n");
81 84

  
82 85
    //TODO: use rtc to make this more accurate
83
    while(1) {
86
    while(i < TOTAL_GAME_TIME) {
84 87
      wl_do();
85 88

  
86 89
      if(ret==0) {
......
93 96
      //update counts when we have waited at least enough time
94 97
      if(ret == 0 && preyBot >= 0) {
95 98
	preyTime[preyBot]++;
99

  
100
	if(i==0) { //time starts on the first real tag
101
	  printf("\nThe race is on!\n");
102
	}
96 103
	i++;
97 104
      }
98 105

  
106
      if((TOTAL_GAME_TIME - i)%600 == 0) {
107
	printf("%d minutes remaining!\n", (TOTAL_GAME_TIME - i)/600);
108
      }
109

  
99 110
      if(i%10==0) {
100 111
	print_stats();
112
	if( TOTAL_GAME_TIME - i <= 100)
113
	  printf("%d...\n", (TOTAL_GAME_TIME - i)/10);
101 114
      }
102 115
    }
103 116

  
117

  
118
    for(i=1;i<NUM_BOTS;i++) {
119
      if(preyTime[i] > maxTime) {
120
	maxTime = preyTime[i];
121
	winner = i;
122
      }
123
    }
124

  
125
    printf("\n\GAME OVER!n\nAAAAAAAAAAND the winner is\nBOT %d!!!!\n", winner);
126

  
104 127
    return 0;
105 128
}
106 129

  

Also available in: Unified diff