void print_finish(t_vm *vm) { t_bin *win; int tmp; win = who_win(vm); if (win->num_plyr < 0) tmp = (-1 * win->num_plyr); else tmp = win->num_plyr; ft_printf("Contestant %d (%s), has won !\n", tmp, win->prog_name); // merde si on a fait un -n if (vm->verbose & 32 || vm->dump > 0) { //print_t_cpu(vm); print_core(vm); } }
int max_cost(Location cur) { Location buf[6]; int i, nextStep, maxCost = 0; cal_roundCost(cur); get_round(cur, buf); for(i = 0; i < 6; i++) if((map[buf[i].x][buf[i].y].type == WAY) && (maxCost < map[buf[i].x][buf[i].y].cost)) { maxCost = map[buf[i].x][buf[i].y].cost; nextStep = i; } if(maxCost == 0) who_win(PLAYER); return nextStep; }
int min_path(Location cur) { Location buf[6]; int next_step = 0; int minPath; int i; cal_allPath(); get_round(cur, buf); minPath = 100; for(i = 0; i < 6; i++) { if(buf[i].path < minPath) { next_step = i; minPath = buf[i].path; } } if(minPath == 100) who_win(PLAYER); return next_step; }
void go_computer() { int i; int oldx = computer.x; int oldy = computer.y; Location buf[6]; if(is_boundary(computer)) who_win(COMPUTER); if(is_inCircle(computer)) { i = max_cost(computer); inCircle = 1; } else i = min_path(computer); switch(i) { case 0: computer.y--; break; case 1: if((computer.x % 2) == 0) { computer.x--; computer.y--; } else { computer.x--; } break; case 2: if((computer.x % 2) == 0) { computer.x--; } else { computer.x--; computer.y++; } break; case 3: computer.y++; break; case 4: if((computer.x % 2) == 0) { computer.x++; } else { computer.x++; computer.y++; } break; case 5: if((computer.x % 2) == 0) { computer.x++; computer.y--; } else { computer.x++; } break; } //end switch if((oldx % 2) == 0) move(oldx, oldy*2); else move(oldx, oldy*2+1); draw_one(WAY); map[oldx][oldy].type = WAY; if((computer.x % 2) == 0) move(computer.x, computer.y*2); else move(computer.x, computer.y*2+1); draw_one(CAT); map[computer.x][computer.y].type = CAT; }