int main(int argc, const char *argv[]) { assert(SIZE1 <= 8*sizeof(bitboard)); assert(TRANSIZE >= ((bitboard)1 << (SIZE1-LOCKSIZE))*31/32); char bookfile[64]; sprintf(bookfile, "book%d%d", WIDTH, HEIGHT); Window wins(argc > 1 ? argv[1] : bookfile); bool ok = true; wins.reset(); wins.refresh(); int c; while ((c = getchar()) != EOF && c != 'q') { switch (c) { case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : ok = wins.play(c - '1'); break; case '\n': ok = wins.solve(); wins.reset(); break; } if (!ok) { putchar('\7'); ok = true; } } printf("Be seeing you...\n"); return 0; }
int ab(int alpha, int beta) { int besti,i,j,h,k,l,val,score; int x,v,work; int nav, av[8]; int64 poscnt; int side, otherside; nodes++; if (plycnt == 41) return DRAW; side = (otherside = plycnt & 1) ^ 1; for (i = nav = 0; ++i <= 7; ) { if ((h = height[i]) <= 6) { if (wins(i,h,3) || colthr[columns[i]] != 0) { if (h+1 <= 6 && wins(i,h+1,1<<otherside)) return LOSE; av[0] = i; /* forget other moves */ while (++i <= 7) if ((h = height[i]) <= 6 && (wins(i,h,3) || colthr[columns[i]] != 0)) return LOSE; nav = 1; break; } if (!(h+1 <= 6 && wins(i,h+1,1<<otherside))) av[nav++] = i; } } if (nav == 0) return LOSE; if (nav == 1) { makemove(av[0]); score = -ab(-beta,-alpha); backmove(); return score; } if ((x = transpose()) != ABSENT) { score = x >> 5; if (score == DRAWLOSE) { if ((beta = DRAW) <= alpha) return score; } else if (score == DRAWWIN) { if ((alpha = DRAW) >= beta) return score; } else return score; /* exact score */ }
Team::Team(QObject *parent, const char *name) : QObject(parent,name) { wins(0); losses(0); ties(0); goals(0); generations(0); Bots.clear(); }
int main() { srand(time(NULL)); win[PLAYERONE] = win[PLAYERTWO] = 0; char grid[ROWS][COLS]; char input; int row = 4; int col = 4; int winning; int which_turn = rand_xoro(); //This is your turn counter, as requested int this_game_player; int player = this_game_player = rand_player(); do { winning = NOTHING; clear_grid(grid); player_prompt(player, which_turn); for(int i=0; !full(grid) && i < 9 && winning == NOTHING; i++) { int result; while ((result = test_input(input, grid, row, col, which_turn)) != 0) { if(result == 1) { printf("Invalid character, 1, 2, or 3 required\n"); read_everything(); } else if(result == 2) { printf("Invalid character, X or O required\n"); read_everything(); } else if(result == 3) { printf(" already taken\n"); read_everything(); } else if(result == 4) { printf("Invalid character\n"); read_everything(); } else if(result == 5) printf("\nNot enough characters!\n"); else if(result == 6) { printf("Invalid row or column selection\n"); read_everything(); } else if(result == 7) { printf("Invalid character selection for your player\n"); //Requested error message for invalid character read_everything(); } player_prompt(player, which_turn); } player = flip(player); which_turn = flip(which_turn); display_grid(grid); winning = test_winnings(grid); if(winning == NOTHING) player_prompt(player, which_turn); else if(winning == XWINS) { printf("Player1 total wins %i, Player 2 total wins %i\n", wins(PLAYERONE), wins(PLAYERTWO)); inc_wins(this_game_player); } else if(winning == OWINS) { inc_wins(this_game_player); printf("Player1 total wins %i, Player 2 total wins %i\n", wins(PLAYERONE), wins(PLAYERTWO)); } else if(winning == TIE) printf("Player1 total wins %i, Player 2 total wins %i\n", wins(PLAYERONE), wins(PLAYERTWO)); } this_game_player = flip(this_game_player); //Alternate players who go first each game. which_turn = rand_xoro(); //Randomize whether X or O comes first next game } while((winning == NOTHING) || (replay() == AGAIN)); }
void Team::randomTeam(unsigned int size) { unsigned int numrules; unsigned int mass; wins(0); losses(0); ties(0); goals(0); name("Team Stochastic"); for (unsigned int i=0; i<size; i++) { numrules = Random::randint(100,200); // pick a random number of rules for each bot mass = Random::randint(1,10); // pick a random number for the bot mass Bot *NewBot = new Bot(this); NewBot->randomBot(numrules, mass); insertBot(NewBot); } }
int get_cell_value(int row, int col) { int rslt; int coeff; if (get_map()->map[row][col] == 'R') coeff = -1; if (get_map()->map[row][col] == 'Y') coeff = 1; if (get_map()->map[row][col] == '-') coeff = 0; if (coeff && wins(row, col)) return (100000 / get_map()->width / get_map()->height * coeff); rslt = get_map()->width - ft_abs(get_map()->width / 2 - col); rslt += get_horizontal_number(row, col) * get_map()->width; rslt += get_vertical_number(row, col) * get_map()->width; rslt += get_diagonal_numbers(row, col) * get_map()->width; rslt *= coeff; return (rslt); }
void GameStorage::increaseWins() { setWins(opponentUniqueId(), wins(opponentUniqueId()) + 1); }