public float heuristicA(Pentago_GameBoard gb) { float value; bool? player; float result = gb.get_player_turn() == IA_PIECES ? float.NegativeInfinity : float.PositiveInfinity; if (gb.get_turn_state() == Pentago_GameBoard.turn_state_addpiece) { gb.switch_turn_state(); } Pentago_Move[] nplays = possible_plays(gb); Pentago_GameBoard ngb; foreach (Pentago_Move move in nplays) { ngb = after_rotate(gb, move); player = boardValue(ngb, out value); #if DEBUG_HEURISTIC_A ngb.print_board(); Console.WriteLine(value + " " + player); #endif if (player != null) { return((player == IA_PIECES) ? 100 : -100); } if ((gb.get_player_turn() == IA_PIECES && value > result) || (gb.get_player_turn() != IA_PIECES && value < result)) { result = value; } } return(result); }
public void apply_move2board(Pentago_GameBoard gb) { gb.board = this.move(gb.board, gb.get_player_turn(), gb.get_turn_state()); if (gb.get_turn_state() == Pentago_GameBoard.turn_state_rotate) { gb.switch_player_turn(); } gb.switch_turn_state(); }
public float heuristicAstar(Pentago_GameBoard gb) { float value; bool? player; bool player_turn = gb.get_player_turn(); bool? player_win = null; bool turn_state = gb.get_turn_state(); if (turn_state == Pentago_GameBoard.turn_state_rotate) { player_turn = !player_turn; if (!study_rotations_on_rotate) { player = boardValueStar(gb, out value); #if DEBUG_HEURISTIC_A_STAR gb.print_board(); Console.WriteLine(printPlayerTurn(gb.get_player_turn())); Console.WriteLine(printTurnState(gb.get_turn_state())); Console.WriteLine(value + " " + player); #endif if (player != null) { return((player == IA_PIECES) ? 100 : -100); } return(value); } } float result = player_turn == IA_PIECES ? float.NegativeInfinity : float.PositiveInfinity; if (turn_state == Pentago_GameBoard.turn_state_addpiece) { gb.switch_turn_state(); } Pentago_GameBoard[] ngbs = next_states(gb); if (turn_state == Pentago_GameBoard.turn_state_addpiece) { gb.switch_turn_state(); } foreach (Pentago_GameBoard ngb in ngbs) { if (turn_state == Pentago_GameBoard.turn_state_addpiece) { ngb.switch_player_turn(); } player = boardValueStar(ngb, out value); #if DEBUG_HEURISTIC_A_STAR ngb.print_board(); Console.WriteLine(printPlayerTurn(gb.get_player_turn()) + " " + printPlayerTurn(ngb.get_player_turn())); Console.WriteLine(printTurnState(gb.get_turn_state()) + " " + printTurnState(ngb.get_turn_state())); Console.WriteLine(value + " " + player); #endif if (player == player_turn) { return((player == IA_PIECES) ? 100 : -100); } if (player != null) { player_win = player; } if ((player_turn == IA_PIECES && value > result) || (player_turn != IA_PIECES && value < result)) { result = value; } } if (player_win != null) { return((player_win == IA_PIECES) ? 100 : -100); } return(result); }