/** * 手順の読み込み */ bool CsaReader::readMoves(std::istream& is, Record& record) { char line[LINE_BUFFER_SIZE]; Move move; while (true) { is.getline(line, sizeof(line)); if (is.eof()) { return true; } if (is.fail()) { Loggers::warning << "file io error: " << __FILE__ << "(" << __LINE__ << ")"; return false; } if (readComment_(line) || readCommand_(line) || readTime_(line)) { continue; } if (!readMove(line, record.getBoard(), move)) { Loggers::warning << "invalid move format: " << __FILE__ << "(" << __LINE__ << ")"; Loggers::warning << "> " << line; return false; } if (!record.makeMove(move)) { Loggers::warning << "invalid move: " << __FILE__ << "(" << __LINE__ << ")"; Loggers::warning << "> " << line; return false; } } }
/* * Main function for handling the "move" command, for executing a move during the game stage. * * @return: -6 if the input move is illegal at this point in the game * -5 if the input tile does not is not occupied by one of the current player's pieces * -2 if illegal coordinates are given as the origin or the destination of the move * -1 if the input was not formatted legally * 1 if an allocation failure occurred * 0 otherwise */ int movePiece(char* command){ int exitcode; PossibleMove* move = readMove(command, &exitcode); if (exitcode != 0){ return exitcode; } LinkedList* possibleMoves = Board_getPossibleMovesOfPiece(&board, move->fromX, move->fromY, 0); if (!possibleMoves){ PossibleMove_free(move); return 1; } if (!PossibleMoveList_contains(possibleMoves, move)){ PossibleMove_free(move); PossibleMoveList_free(possibleMoves); return -6; } Board_copy(&board, move->board); display(); PossibleMove_free(move); PossibleMoveList_free(possibleMoves); turn = !turn; return 0; }
void play(char *position) { pieces = initPieces(position); char player = 'w'; int from, to; int legal; while(1) { if(isMate(pieces, player)) return; char *posString = createPosString(pieces); printBoard(posString); free(posString); from = -1; to = -1; legal = 0; printMoves(pieces, player); while(!legal) { readMove(&from, &to); legal = legalMove(pieces, from, to, player); char *fromSt, *toSt; if(!legal) { printf("%s %s is illegal\n", fromSt = stringPosToSquare(from), toSt = stringPosToSquare(to)); free(fromSt); free(toSt); } } movePiece(pieces, from, to); player = player == 'w' ? 'b' : 'w'; } }
void Board::get_move(bool is_2_player_game, AI &_AI,int cur_player){ Board cur_board_ = *this; if (is_2_player_game == false && cur_player == _AI._AI_player) place(_AI.get_move(cur_board_, cur_player,-(1<<30),(1<<30)).position, cur_player); else{ while (readMove(cur_player) == false); } return; }
SimulatedClient::SimulatedClient(int addr, int totalClientPosition, int totalServer){ setMyAddr(addr); setTotalClientPosition(totalClientPosition); _mobilityPath = new vector<int>(); _timeSlot = new vector<int>(); readMove(); readTimeSlot(); readMobilityPattern(); setMobilityPathLength(_mobilityPath->size()); setStartClientPosition(_mobilityPath->at(0)); setCurrentClientPosition(_startClientPosition); _totalServer = totalServer; }
int printMoveValue(char* command){ int exitcode; int depth; int bestOffset = 0; if (command[10] == 'b'){ depth = computeBestDepth(); bestOffset = 3; } else{ if (sscanf(command, "get_score %d", &depth) < 0){ return -1; } } if (!strstr(command, "move") && !strstr(command, "castle")){ return -1; } if (strstr(command, "move")){ PossibleMove* move = readMove(command + 12 + bestOffset, &exitcode); if (exitcode != 0){ // illegal input or illegal move return exitcode; } else{ int score = alphabeta(move, depth, !turn, INT_MIN, INT_MAX); printf("%d\n", score); PossibleMove_free(move); } } // castling move else{ int rookX, rookY; exitcode = readTile(command + 19, &rookX, &rookY); if (exitcode == 0){ PossibleMove* castlingMove = PossibleMove_new(rookX, rookY, 0, 0, 0, &board); int score = alphabeta(castlingMove, depth, !turn, INT_MIN, INT_MAX); printf("%d\n", score); PossibleMove_free(castlingMove); } } return exitcode; }
int main(void) { initGame(); int curPlayer = 0; do { if (++curPlayer > numPlayers) { curPlayer = 1; turnCounter++; } if (curPlayer == me) { makeMove(); } else { readMove(curPlayer); } // printGameState(); } while (p[curPlayer].cash < WIN_CASH); if (LOOP_AT_END) { while (true); } }