#include #include #include #include "../include/language.h" #include "../include/parser.h" #include "../include/simulator.h" using namespace std; char charToObj( char x ) { switch (x) { case '#': return WALL; case '.': return EMPTY; case '+': return ANTRED; case '-': return ANTBLACK; } if ( x < '1' || x > '9' ) return 127; return EMPTY; } uchar charToHome( char x, int col ) { if ( x == '+' && col == RED ) return homeCode; if ( x == '-' && col == BLACK ) return homeCode; return 0; } char objToChar( char x , uchar red, uchar black) { switch (x) { case WALL: return '#'; case EMPTY: return '.'; case ANTRED: return 'R'; case ANTBLACK: return 'B'; case '+': if (red & homeCode) return '+'; case '-': if (black & homeCode) return '-'; } return 'X'; } char charToFood( char x ) { if ( x < '1' || x > '9' ) return (char)0; return (char)(x - '0'); } int parseMap(char* filename, Map & map) { char inp[MAX_LENGTH]; FILE * fin = fopen(filename, "r"); if(!fin) return 1; fgets(inp, MAX_LENGTH, fin); map.sizex = atoi(inp); fgets(inp, MAX_LENGTH, fin); map.sizey = atoi(inp); for (int r=0; r 9 ? 'F' : map.foodcount[i][j]) << " "; else cout << objToChar(map.object[i][j], map.marker[RED][i][j], map.marker[BLACK][i][j]) << " "; cout << endl; } return 0; } int printTrails(Map & map, uchar col, uchar mask) { assert(col == RED || col == BLACK); for (int j=0; j 9 ? 'F' : map.foodcount[i][j]) << " "; else cout << objToChar(map.object[i][j], map.marker[RED][i][j], map.marker[BLACK][i][j]) << " "; cout << endl; } return 0; } int dumpState(Map & map) { for (int r=0; r 0) { printf("%d food; ", map.foodcount[c][r]); } if (map.marker[RED][c][r] & homeCode) { printf("red hill; "); } if (map.marker[BLACK][c][r] & homeCode) { printf("black hill; "); } // Check marks left by RED ants if (map.marker[RED][c][r] & ALY_MARKER_MASK) { printf("red marks: "); for (int i=0; i<6; i++) if (map.marker[RED][c][r] & markerCode(i)) printf("%d",i); printf("; "); } // Check marks left by BLACK ants if (map.marker[BLACK][c][r] & ALY_MARKER_MASK) { printf("black marks: "); for (int i=0; i<6; i++) if (map.marker[BLACK][c][r] & markerCode(i)) printf("%d",i); printf("; "); } // Check if this cell contains a RED ant if (map.object[c][r] == ANTRED) { // Construct point to pass in to LTank's findAnt function Point thisPoint; thisPoint.x = c; thisPoint.y = r; Ant & ant = findAnt(thisPoint); printf("red ant of id %d, dir %d, food %d, state %d, resting %d", ant.id, ant.dir, ant.has_food, ant.pc, ant.resting); } // Check if this cell contains a BLACK ant if (map.object[c][r] == ANTBLACK) { // Construct point to pass in to LTank's findAnt function Point thisPoint; thisPoint.x = c; thisPoint.y = r; Ant & ant = findAnt(thisPoint); printf("black ant of id %d, dir %d, food %d, state %d, resting %d", ant.id, ant.dir, ant.has_food, ant.pc, ant.resting); } printf("\n"); } } return 0; }