public int ScoreVictoryTry() { // This is going to do the same danger(close to victory) for our last movement DangerEvaluation evaluation = new DangerEvaluation(playing_board.last_ai_movement.row, playing_board.last_ai_movement.col); evaluation = HorizontalDanger(playing_board.last_ai_movement.row, playing_board.last_ai_movement.col, evaluation, ESlotStatus.AI); evaluation = VerticalDanger(playing_board.last_ai_movement.row, playing_board.last_ai_movement.col, evaluation, ESlotStatus.AI); evaluation = DiagonalNegativeDanger(playing_board.last_ai_movement.row, playing_board.last_ai_movement.col, evaluation, ESlotStatus.AI); evaluation = DiagonalPositiveDanger(playing_board.last_ai_movement.row, playing_board.last_ai_movement.col, evaluation, ESlotStatus.AI); last_self_evaluation = evaluation; int risk = last_self_evaluation.MaxRisk(); switch (risk) { case 1: return(60); case 2: return(80); case 3: return(110); case 4: return(200); default: break; } return(0); }
public int ScoreBlocker() { DangerEvaluation evaluation = new DangerEvaluation(playing_board.last_player_movement.row, playing_board.last_player_movement.col); evaluation = HorizontalDanger(playing_board.last_player_movement.row, playing_board.last_player_movement.col, evaluation, ESlotStatus.Player); evaluation = VerticalDanger(playing_board.last_player_movement.row, playing_board.last_player_movement.col, evaluation, ESlotStatus.Player); evaluation = DiagonalNegativeDanger(playing_board.last_player_movement.row, playing_board.last_player_movement.col, evaluation, ESlotStatus.Player); evaluation = DiagonalPositiveDanger(playing_board.last_player_movement.row, playing_board.last_player_movement.col, evaluation, ESlotStatus.Player); last_evaluation = evaluation; int total_danger = last_evaluation.MaxRisk(); bool can_be_blocked = CanBeBlocked(last_evaluation); if (!can_be_blocked) { total_danger -= 100; } switch (total_danger) { case 1: return(33); case 2: return(50); case 3: return(99); case 4: return(130); default: return(10); } }
Movement GetWinningMovement() { // What this should do: // Iterate over our movements, calculate the danger of the movement and // select the one that is going to give us the most for our buck! foreach (Movement current_movement in playing_board.ai_movements) { DangerEvaluation evaluation = EvaluateMovement(current_movement); if (last_self_evaluation.MaxRisk() < evaluation.MaxRisk()) { last_self_evaluation = evaluation; } } EDirection direction_to_move = last_self_evaluation.DangerDirection(); int row = playing_board.last_ai_movement.row; int col = playing_board.last_ai_movement.col; Movement movement = new Movement(row, col); switch (direction_to_move) { case EDirection.Horizontal: // This needs to be extracted and deal with a more complex logic. // Its being repeated at make movement if (ValidIndex(col + 1) && playing_board.board[row, col + 1] == ESlotStatus.Empty) { return(new Movement(row, col + 1)); } if (ValidIndex(col - 1) && playing_board.board[row, col - 1] == ESlotStatus.Empty) { return(new Movement(row, col - 1)); } break; case EDirection.Vertical: if (ValidIndex(row + 1) && playing_board.board[row + 1, col] == ESlotStatus.Empty) { return(new Movement(row + 1, col)); } if (ValidIndex(row - 1) && playing_board.board[row - 1, col] == ESlotStatus.Empty) { return(new Movement(row - 1, col)); } break; case EDirection.DiagonalNeg: if ((ValidIndex(row - 1) && ValidIndex(col - 1)) && playing_board.board[row - 1, col - 1] == ESlotStatus.Empty) { return(new Movement(row - 1, col - 1)); } if ((ValidIndex(row + 1) && ValidIndex(col + 1)) && playing_board.board[row + 1, col + 1] == ESlotStatus.Empty) { return(new Movement(row + 1, col + 1)); } break; case EDirection.DiagonalPos: if ((ValidIndex(row + 1) && ValidIndex(col - 1)) && playing_board.board[row + 1, col - 1] == ESlotStatus.Empty) { return(new Movement(row + 1, col - 1)); } if ((ValidIndex(row - 1) && ValidIndex(col + 1)) && playing_board.board[row - 1, col + 1] == ESlotStatus.Empty) { return(new Movement(row - 1, col + 1)); } break; case EDirection.ItsAllFine: break; default: break; } return(GetRandomMovement()); }