/* * asetblitz * * Usage: asetblitz handle rating won lost drew RD * * This command allows admins to set a user's statistics for Blitz games. * The parameters are self-explanatory: rating, # of wins, # of losses, * # of draws, and ratings deviation. */ int com_asetzh(int p, param_list param) { int p1, connected; if (!FindPlayer(p, param[0].val.word, &p1, &connected)) return COM_OK; if (CheckPFlag(p1, PFLAG_REG)) { SetRating(p1, param, &player_globals.parray[p1].z_stats); player_save(p1); UpdateRank(TYPE_CRAZYHOUSE, player_globals.parray[p1].name, &player_globals.parray[p1].z_stats, player_globals.parray[p1].name); } else pprintf(p, "%s is unregistered. Can't modify rating.\n", player_globals.parray[p1].name); if (!connected) player_remove(p1); return COM_OK; }
void CUIBagWnd::UpdateBuyPossibility() { u32 sz = m_allItems.size(); for (u32 i = 0; i<sz; i++) { if (IsInBag(m_allItems[i])) { if (m_info[m_allItems[i]->m_index].bought) { m_allItems[i]->SetColor(0x00ffffff); } else if (UpdateRank(m_allItems[i])) // update price if there no restriction for rank { if (UpdatePrice(m_allItems[i], i)) { if (m_info[i].external) SET_EXTERNAL_COLOR(m_allItems[i]); } } } } }
void UpdateStates(const tMove *OpponentMove) { // --- Get moved piece, update position --- tPiece *moved_piece = GetPieceByPos(OpponentMove->x, OpponentMove->y); // - Sanity ASSERT( moved_piece ); ASSERT( moved_piece->Team == !gMyColour ); // - Only scouts can move multiple squares if( moved_piece->Rank == RANK_UNKNOWN && OpponentMove->dist > 1 ) UpdateRank(moved_piece, '9'); // - Update position int newx = moved_piece->X, newy = moved_piece->Y; switch(OpponentMove->dir) { case DIR_INVAL: break; case DIR_LEFT: newx -= OpponentMove->dist; break; case DIR_RIGHT: newx += OpponentMove->dist; break; case DIR_UP: newy -= OpponentMove->dist; break; case DIR_DOWN: newy += OpponentMove->dist; break; } tPiece *my_piece = GetPieceByPos(newx, newy); // Check if one of my pieces has been taken switch( OpponentMove->result ) { case RESULT_ILLEGAL: break; case RESULT_INVAL: break; case RESULT_OK: MovePieceTo(moved_piece, newx, newy); break; case RESULT_KILL: case RESULT_VICTORY: UpdateRank(moved_piece, OpponentMove->attacker); PieceExposed(my_piece); RemovePiece(my_piece); MovePieceTo(moved_piece, newx, newy); break; case RESULT_DIES: UpdateRank(moved_piece, OpponentMove->attacker); PieceExposed(my_piece); RemovePiece(moved_piece); break; case RESULT_BOTHDIE: UpdateRank(moved_piece, OpponentMove->attacker); RemovePiece(moved_piece); PieceExposed(my_piece); RemovePiece(my_piece); break; } // Update rank if revealed if( moved_piece->Rank == RANK_UNKNOWN ) UpdateRank(moved_piece, gaBoardState[moved_piece->Y*giBoardWidth+moved_piece->X]); // - Update piece states DEBUG("Updating piece states"); for( int y = 0; y < giBoardHeight; y ++ ) { for( int x = 0; x < giBoardWidth; x ++ ) { char c = gaBoardState[y*giBoardWidth+x]; if( c == '.' ) continue; if( c == '+' ) continue; tPiece *p = GetPieceByPos(x, y); if(!p) DEBUG("c = %c", c); ASSERT(p); if( p->Team == gMyColour ) continue ; if( p->Rank == RANK_UNKNOWN && c != '#' ) UpdateRank(p, c); } } }
void AI_HandleMove(int bMyMove, const tMove *Move) { if( gbFirstTurn ) { gbFirstTurn = false; AI_int_InitialiseBoardState(); // Reverse the first move if( Move->dir != DIR_INVAL ) { tPiece *p; switch(Move->dir) { case DIR_INVAL: ASSERT(Move->dir != DIR_INVAL); break; case DIR_LEFT: p = GetPieceByPos( Move->x-1, Move->y ); break ; case DIR_RIGHT: p = GetPieceByPos( Move->x+1, Move->y ); break ; case DIR_UP: p = GetPieceByPos( Move->x, Move->y-1 ); break ; case DIR_DOWN: p = GetPieceByPos( Move->x, Move->y+1 ); break ; } MovePieceTo( p, Move->x, Move->y ); p->StartX = Move->x; p->StartY = Move->y; } } if(Move->result == RESULT_VICTORY) { // TODO: Distiguish between victory conditions? // - Note flag location? // TODO: Save back initial board state DB_WriteBackInitialState(gsOpponentDbFilename, !gMyColour, gpCurrentGameState->Opponent.Pieces); } if( !bMyMove ) { if( Move->dir != DIR_INVAL ) UpdateStates(Move); } else { tPiece *p = GetPieceByPos(Move->x, Move->y); ASSERT(p); int newx = p->X, newy = p->Y; switch(Move->dir) { case DIR_INVAL: break; case DIR_LEFT: newx -= Move->dist; break; case DIR_RIGHT: newx += Move->dist; break; case DIR_UP: newy -= Move->dist; break; case DIR_DOWN: newy += Move->dist; break; } tPiece *target = GetPieceByPos(newx, newy); switch(Move->result) { case RESULT_ILLEGAL: break; case RESULT_INVAL: break; case RESULT_OK: MovePieceTo(p, newx, newy); break; case RESULT_KILL: UpdateRank(target, Move->defender); RemovePiece(target); MovePieceTo(p, newx, newy); PieceExposed(p); // TODO: Update oponent's view giTurnsSinceLastTake = 0; break; case RESULT_DIES: case RESULT_VICTORY: UpdateRank(target, Move->defender); PieceExposed(p); RemovePiece(p); giTurnsSinceLastTake = 0; break; case RESULT_BOTHDIE: UpdateRank(target, Move->defender); PieceExposed(p); RemovePiece(p); RemovePiece(target); giTurnsSinceLastTake = 0; break; } } }
void AI_int_InitialiseBoardState(void) { int piece_index = 0; int my_piece_index = 0; for( int y = 0; y < giBoardHeight; y ++ ) { for( int x = 0; x < giBoardWidth; x ++ ) { tPiece *p; char b; b = gaBoardState[y*giBoardWidth+x]; if( b == '.' ) continue ; if( b == '+' ) { gpCurrentGameState->BoardState[ y*giBoardWidth+x ].Team = 3; continue ; } if( b == '#' ) { if( piece_index >= N_PIECES ) { piece_index ++; continue ; } p = &gpCurrentGameState->Opponent.Pieces[piece_index++]; p->Rank = RANK_UNKNOWN; p->X = x; p->StartX = x; p->Y = y; p->StartY = y; p->bHasMoved = false; p->Team = !gMyColour; gpCurrentGameState->BoardState[ y*giBoardWidth+x ].Team = 2; gpCurrentGameState->BoardState[ y*giBoardWidth+x ].Index = piece_index - 1; DEBUG("Enemy at %i,%i", x, y); } else { if( my_piece_index >= N_PIECES ) { my_piece_index ++; continue ; } p = &gpCurrentGameState->MyActual.Pieces[my_piece_index++]; p->X = x; p->Y = y; p->Team = gMyColour; UpdateRank(p, b); gpCurrentGameState->MyActual.nRanks[p->Rank] ++; gpCurrentGameState->BoardState[ y*giBoardWidth+x ].Team = 1; gpCurrentGameState->BoardState[ y*giBoardWidth+x ].Index = my_piece_index - 1; } } } gpCurrentGameState->Opponent.nPieces = piece_index; if( piece_index > N_PIECES ) DEBUG("GAH! Too many opposing pieces (%i > 40)", piece_index); if( my_piece_index > N_PIECES ) DEBUG("GAH! Too many of my pieces (%i > 40)", my_piece_index); // Catch for if I don't put enough pieces out (shouldn't happen) while( my_piece_index < N_PIECES ) { gpCurrentGameState->MyActual.Pieces[my_piece_index].bDead = true; gpCurrentGameState->MyActual.Pieces[my_piece_index].Rank = RANK_UNKNOWN; my_piece_index ++; } // Load guesses at what each piece is DB_LoadGuesses(gsOpponentDbFilename, !gMyColour); gpCurrentGameState->Opponent.bGuessValid = true; }