Пример #1
0
    void Start()
    {
        squares_dest_rot = new int[4];
        for (int i = 0; i < 4; i++)
        {
            squares_dest_rot[i] = 0;
        }

        default_rotations    = new Quaternion[4];
        default_rotations[0] = Quaternion.Euler(-90, 0, 0);
        default_rotations[1] = Quaternion.Euler(-90, 90, 0);
        default_rotations[2] = Quaternion.Euler(-90, 180, 0);
        default_rotations[3] = Quaternion.Euler(-90, 270, 0);

        default_y_position = squares[0].transform.localPosition;

        squareRotating = null;

        visual_cue   = GetComponentInChildren <Light>();
        rotationsGUI = GetComponentInChildren <Canvas>();
        HideRotationGUI();
        gameboard = new Pentago_GameBoard();

        startGame();
    }
Пример #2
0
    void IA_place_piece(bool IA2 = false)
    {
        if (!IA2 && iaThread != null && !iaThread.concluded)
        {
            return;
        }
        if (IA2 && iaThread2 != null && !iaThread2.concluded)
        {
            return;
        }
        if (GAMESUBSTATE_IS_PLACING_PIECE)
        {
            return;
        }
        Pentago_Move place_move = IA2 ? iaThread2.moves[0] : iaThread.moves[0];

        //Debug.Log((gameboard.get_player_turn() == Pentago_GameBoard.blacks_turn) + "__" + (gameboard.get_turn_state() == Pentago_GameBoard.turn_state_addpiece));
        place_move.apply_move2board(gameboard);
        // Debug.Log(gameboard.get_player_turn() + "__" + gameboard.get_turn_state());


        int x, y;

        Pentago_GameBoard.board_index_to_position(place_move.index, out x, out y, out square2placePiece);
        new_piece_hole = squares[square2placePiece].transform.parent.gameObject.GetComponentsInChildren <Hole>().First(
            o => o.x == x && o.y == y).gameObject.transform;

        GAMESUBSTATE_IS_PLACING_PIECE = true;
        StartCoroutine("PLACE_PIECE_COUROUTINE");
    }
    static void printAllMoves(List <Pentago_Move> allMoves, Pentago_GameBoard board)
    {
        int i = 0;

        foreach (Pentago_Move move in allMoves)
        {
            if (board.get_player_turn() == Pentago_GameBoard.whites_turn)
            {
                Console.Write("White ");
            }
            else
            {
                Console.Write("Black ");
            }
            if (board.get_turn_state() == Pentago_GameBoard.turn_state_rotate)
            {
                Console.WriteLine("rotate");
            }
            else
            {
                Console.WriteLine("place");
            }
            move.apply_move2board(board);
            board.print_board();
            i++;
            if (i % 2 == 0)
            {
                Console.WriteLine("|-|-|-|-|-|-|-|-|");
            }
        }
    }
Пример #4
0
    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);
    }
Пример #5
0
 void bakeMovesMainDiagAbove()
 {
     MovesMainDiagAbove    = new Pentago_Move[21];
     MovesMainDiagAbove[0] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(0, 0, 0)];
     MovesMainDiagAbove[1] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(1, 0, 0)];
     MovesMainDiagAbove[2] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(2, 0, 0)];
     MovesMainDiagAbove[3] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(1, 1, 0)];
     MovesMainDiagAbove[4] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(2, 1, 0)];
     MovesMainDiagAbove[5] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(2, 2, 0)];
     for (int i = 6; i < 15; i++)
     {
         for (int x = 0; x < 3; x++)
         {
             for (int y = 0; y < 3; y++)
             {
                 MovesMainDiagAbove[i] = new Pentago_Move(x, y, 1);
             }
         }
     }
     MovesMainDiagAbove[15] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(0, 0, 3)];
     MovesMainDiagAbove[16] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(1, 0, 3)];
     MovesMainDiagAbove[17] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(2, 0, 3)];
     MovesMainDiagAbove[18] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(1, 1, 3)];
     MovesMainDiagAbove[19] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(2, 1, 3)];
     MovesMainDiagAbove[20] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(2, 2, 3)];
 }
Пример #6
0
 void bakeMovesAntiDiagAbove()
 {
     MovesAntiDiagAbove = new Pentago_Move[21];
     for (int i = 0; i < 9; i++)
     {
         for (int x = 0; x < 3; x++)
         {
             for (int y = 0; y < 3; y++)
             {
                 MovesAntiDiagAbove[i] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(x, y, 0)];
             }
         }
     }
     MovesAntiDiagAbove[9]  = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(0, 0, 1)];
     MovesAntiDiagAbove[10] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(1, 0, 1)];
     MovesAntiDiagAbove[11] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(2, 0, 1)];
     MovesAntiDiagAbove[12] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(1, 1, 1)];
     MovesAntiDiagAbove[13] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(2, 1, 1)];
     MovesAntiDiagAbove[14] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(2, 2, 1)];
     MovesAntiDiagAbove[15] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(0, 0, 2)];
     MovesAntiDiagAbove[16] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(1, 0, 2)];
     MovesAntiDiagAbove[17] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(2, 0, 2)];
     MovesAntiDiagAbove[18] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(1, 1, 2)];
     MovesAntiDiagAbove[19] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(2, 1, 2)];
     MovesAntiDiagAbove[20] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(2, 2, 2)];
 }
Пример #7
0
    void countShortLine(Pentago_GameBoard gb, int[] line, out int whiteCount, out int blackCount)
    {
        int whites = 0;
        int blacks = 0;

        foreach (int i in line)
        {
            if (gb.board[i] == HOLESTATE.has_white)
            {
                whites++;
            }
            else if (gb.board[i] == HOLESTATE.has_black)
            {
                blacks++;
            }
        }
        whiteCount = 0;
        blackCount = 0;
        if (blacks == 0 && whites > 0)
        {
            whiteCount = whites;
        }
        else if (whites == 0 && blacks > 0)
        {
            blackCount = blacks;
        }
#if DEBUG_HEURISTIC_A
        Console.WriteLine("W " + whiteCount + "  B " + blackCount);
#endif
    }
Пример #8
0
 HOLESTATE[] rotate(HOLESTATE[] gb, Pentago_Move move)
 {
     HOLESTATE[] new_gb = (HOLESTATE[])gb.Clone();
     if (move.rotDir == Pentago_Move.rotate_clockwise)
     {
         for (int x = 0; x < 3; ++x)
         {
             for (int y = 0; y < 3; ++y)
             {
                 new_gb[Pentago_GameBoard.board_position_to_index(Math.Abs(2 - y), x, move.square2rotate)]
                     = gb[Pentago_GameBoard.board_position_to_index(x, y, move.square2rotate)];
             }
         }
     }
     else
     {
         for (int x = 0; x < 3; ++x)
         {
             for (int y = 0; y < 3; ++y)
             {
                 new_gb[Pentago_GameBoard.board_position_to_index(y, Math.Abs(2 - x), move.square2rotate)]
                     = gb[Pentago_GameBoard.board_position_to_index(x, y, move.square2rotate)];
             }
         }
     }
     return(new_gb);
 }
    static void initialize_test_gameboards()
    {
        const HOLESTATE B = HOLESTATE.has_black;
        const HOLESTATE W = HOLESTATE.has_white;
        const HOLESTATE E = HOLESTATE.is_empty;

        board1 = new Pentago_GameBoard(
            new HOLESTATE[] {
            B, B, B, E, E, E,
            W, W, W, B, B, B,
            B, B, B, W, W, W,

            W, W, W, B, B, B,
            B, B, B, W, W, W,
            W, W, W, E, E, E
        }
            , Pentago_GameBoard.whites_turn, Pentago_GameBoard.turn_state_addpiece);

        board1r = new Pentago_GameBoard(
            new HOLESTATE[] {
            B, B, B, E, E, E,
            W, W, W, B, B, B,
            B, B, B, W, W, W,

            W, W, W, B, B, B,
            B, B, B, W, W, W,
            W, W, W, E, E, E
        }
            , Pentago_GameBoard.whites_turn, Pentago_GameBoard.turn_state_rotate);
    }
Пример #10
0
    bool?checkAlmost(Pentago_GameBoard gb, int whiteCount, int blackCount, ref int whiteAlmost, ref int blackAlmost)
    {
        if (whiteCount > 4)
        {
            whiteAlmost++;
#if DEBUG_HEURISTIC_A
            Console.WriteLine("white almost");
#endif
        }
        if (blackCount > 4)
        {
            blackAlmost++;
#if DEBUG_HEURISTIC_A
            Console.WriteLine("black almost");
#endif
        }
        if (whiteAlmost >= 2 && gb.get_player_turn() == IA_PIECES_WHITES)
        {
            return(IA_PIECES_WHITES);
        }
        if (blackAlmost >= 2 && gb.get_player_turn() == IA_PIECES_BLACKS)
        {
            return(IA_PIECES_BLACKS);
        }
        return(null);
    }
Пример #11
0
 static void applyMoves(Pentago_Move[] moves, Pentago_GameBoard board)
 {
     foreach (Pentago_Move move in moves)
     {
         move.apply_move2board(board);
     }
 }
Пример #12
0
    bool?checkAlmostStar(bool?player, Pentago_GameBoard gb, ref int whiteCount, ref int blackCount, ref int whiteAlmost, ref int blackAlmost)
    {
        if (player != null)
        {
            return(player);
        }
        if (whiteCount > 4)
        {
            whiteAlmost++;
#if DEBUG_HEURISTIC_A_STAR
            Console.WriteLine("white almost");
#endif
        }
        if (blackCount > 4)
        {
            blackAlmost++;
#if DEBUG_HEURISTIC_A_STAR
            Console.WriteLine("black almost");
#endif
        }
        bool whiteWin = false;
        if (whiteAlmost >= 2)
        {
            whiteWin = true;
        }
        bool blackWin = false;
        if (blackAlmost >= 2)
        {
            blackWin = true;
        }
        return(checkWinStar(whiteWin, blackWin, gb.get_player_turn()));
    }
Пример #13
0
        static void initialize_test_gameboards()
        {
            const Pentago_GameBoard.hole_state B = Pentago_GameBoard.hole_state.has_black;
            const Pentago_GameBoard.hole_state W = Pentago_GameBoard.hole_state.has_white;
            const Pentago_GameBoard.hole_state E = Pentago_GameBoard.hole_state.is_empty;

            board1 = new Pentago_GameBoard(
                new Pentago_GameBoard.hole_state[] {
                B, B, B, E, E, E,
                W, W, W, B, B, B,
                B, B, B, W, W, W,

                W, W, W, B, B, B,
                B, B, B, W, W, W,
                W, W, W, E, E, E
            }
                , Pentago_GameBoard.whites_turn, Pentago_GameBoard.turn_state_addpiece);

            board1r = new Pentago_GameBoard(
                new Pentago_GameBoard.hole_state[] {
                B, B, B, E, E, E,
                W, W, W, B, B, B,
                B, B, B, W, W, W,

                W, W, W, B, B, B,
                B, B, B, W, W, W,
                W, W, W, E, E, E
            }
                , Pentago_GameBoard.whites_turn, Pentago_GameBoard.turn_state_rotate);
        }
Пример #14
0
    /// <summary>
    /// applies 2 steps immiditaly, not made for standard minimax
    /// </summary>
    /// <param name="gb"></param>
    /// <returns></returns>
    public Pentago_GameBoard.hole_state[] move2steped(Pentago_GameBoard.hole_state[] gb, bool turn, bool turnstate)
    {
        Pentago_GameBoard.hole_state[] new_gb = (Pentago_GameBoard.hole_state[])gb.Clone();

        new_gb[index]    //Pentago_GameBoard.board_postion_to_index(hole2place_x, hole2place_y,square2place)]
            = turn == Pentago_GameBoard.blacks_turn ? Pentago_GameBoard.hole_state.has_black : Pentago_GameBoard.hole_state.has_white;

        if (rotDir == rotate_clockwise)
        {
            for (int x = 0; x < 3; ++x)
            {
                for (int y = 0; y < 3; ++y)
                {
                    new_gb[Pentago_GameBoard.board_position_to_index(Math.Abs(2 - y), x, square2rotate)]
                        = gb[Pentago_GameBoard.board_position_to_index(x, y, square2rotate)];
                }
            }
        }
        else
        {
            for (int x = 0; x < 3; ++x)
            {
                for (int y = 0; y < 3; ++y)
                {
                    new_gb[Pentago_GameBoard.board_position_to_index(y, Math.Abs(2 - x), square2rotate)]
                        = gb[Pentago_GameBoard.board_position_to_index(x, y, square2rotate)];
                }
            }
        }

        return(new_gb);
    }
 static void applyMoves(Pentago_Move[] moves, Pentago_GameBoard board, ref List <Pentago_Move> allMoves)
 {
     foreach (Pentago_Move move in moves)
     {
         move.apply_move2board(board);
         allMoves.Add(move);
     }
 }
Пример #16
0
    static public void testPerformnace(int numOfBorads)
    {
        Pentago_GameBoard[] testBoardsWhites = new Pentago_GameBoard[numOfBorads];
        Pentago_GameBoard[] testBoardsBlacks = new Pentago_GameBoard[numOfBorads];

        for (int i = 0; i < numOfBorads; i++)
        {
            int numPieces = GenerateRandomBoard.GetRandomNumber(0, 17);
            Console.WriteLine("Num of pieces " + numPieces);
            GenerateRandomBoard rndBoard;

            Console.WriteLine("white");

            rndBoard = new GenerateRandomBoard(numPieces - 1, true); // -1 prencipio de iguldade de peças do tabuleiro
            rndBoard.generateNewBoard();
            testBoardsWhites[i] = rndBoard.Pentago_gb;
            testBoardsWhites[i].print_board();

            Console.WriteLine("black");

            rndBoard = new GenerateRandomBoard(numPieces, false);
            rndBoard.generateNewBoard();
            testBoardsBlacks[i] = rndBoard.Pentago_gb;
            testBoardsBlacks[i].print_board();
        }

        Pentago_Rules wrules = new Pentago_Rules(Pentago_Rules.EvaluationFunction.controlHeuristic,
                                                 Pentago_Rules.NextStatesFunction.all_states,
                                                 Pentago_Rules.IA_PIECES_WHITES, false);
        MINMAX        test_w = new MINMAX(MINMAX.VERSION.minmax, wrules, 6);
        Pentago_Rules brules = new Pentago_Rules(Pentago_Rules.EvaluationFunction.controlHeuristic,
                                                 Pentago_Rules.NextStatesFunction.all_states,
                                                 Pentago_Rules.IA_PIECES_BLACKS, false);
        MINMAX test_b = new MINMAX(MINMAX.VERSION.minmax, brules, 6);

        TimeSpan test1 = Performance.PerformanceTimes(test_w, testBoardsWhites);
        TimeSpan test2 = Performance.PerformanceTimes(test_b, testBoardsBlacks);

        TimeSpan ts = test1.Add(test2);

        string elapsedTime1 = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                            test1.Hours, test1.Minutes, test1.Seconds,
                                            test1.Milliseconds / 10);

        string elapsedTime2 = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                            test2.Hours, test2.Minutes, test2.Seconds,
                                            test2.Milliseconds / 10);

        // Format and display the TimeSpan value.
        string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                           ts.Hours, ts.Minutes, ts.Seconds,
                                           ts.Milliseconds / 10);

        Console.WriteLine("RunTime " + elapsedTime);
        Console.WriteLine("RunTime 1 " + elapsedTime1);
        Console.WriteLine("RunTime 2 " + elapsedTime2);
    }
Пример #17
0
 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();
 }
Пример #18
0
 /// <summary>
 /// copies a square from one board to a square in another board
 /// </summary>
 void copy_square2(HOLESTATE[] scr, HOLESTATE[] dst, int src_square, int dst_square)
 {
     for (int i = 0; i < 3; i++)
     {
         for (int a = 0; a < 3; a++)
         {
             dst[Pentago_GameBoard.board_position_to_index(i, a, dst_square)] =
                 scr[Pentago_GameBoard.board_position_to_index(i, a, src_square)];
         }
     }
 }
Пример #19
0
 void bakeMovesSquare0Triang()
 {
     MovesSquare0Triang = new Pentago_Move[6] {
         all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(0, 0, 0)],
         all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(1, 0, 0)],
         all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(2, 0, 0)],
         all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(1, 1, 0)],
         all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(2, 1, 0)],
         all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(2, 2, 0)]
     };
 }
Пример #20
0
    public override string ToString()
    {
        int x, y, sqr;

        Pentago_GameBoard.board_index_to_position(index, out x, out y, out sqr);

        return("place(" + x + "," + y + "," + sqr + ")" +
               "  rot(" + square2rotate + ","
               + (rotDir == rotate_anticlockwise? "anticlock":"clock")
               + "," + ")");
    }
Пример #21
0
    static void available_diamond(HOLESTATE[] gb, int square, out int available4whites, out int available4blacks)
    {
        available4whites = 0;
        available4blacks = 0;

        HOLESTATE H10 = gb[Pentago_GameBoard.board_position_to_index(1, 0, square)];
        HOLESTATE H12 = gb[Pentago_GameBoard.board_position_to_index(1, 2, square)];
        HOLESTATE H01 = gb[Pentago_GameBoard.board_position_to_index(0, 1, square)];
        HOLESTATE H21 = gb[Pentago_GameBoard.board_position_to_index(2, 1, square)];

        /* if (H10 != HOLESTATE.has_black) available4whites++;
         * if (H12 != HOLESTATE.has_black) available4whites++;
         * if (H01 != HOLESTATE.has_black) available4whites++;
         * if (H21 != HOLESTATE.has_black) available4whites++;
         *
         * if (H10 != HOLESTATE.has_white) available4blacks++;
         * if (H12 != HOLESTATE.has_white) available4blacks++;
         * if (H01 != HOLESTATE.has_white) available4blacks++;
         * if (H21 != HOLESTATE.has_white) available4blacks++;*/

        if (H10 != HOLESTATE.has_black && H21 != HOLESTATE.has_black)
        {
            available4whites++;
        }
        if (H12 != HOLESTATE.has_black && H01 != HOLESTATE.has_black)
        {
            available4whites++;
        }
        if (H01 != HOLESTATE.has_black && H10 != HOLESTATE.has_black)
        {
            available4whites++;
        }
        if (H21 != HOLESTATE.has_black && H12 != HOLESTATE.has_black)
        {
            available4whites++;
        }

        if (H10 != HOLESTATE.has_white && H21 != HOLESTATE.has_white)
        {
            available4blacks++;
        }
        if (H12 != HOLESTATE.has_white && H01 != HOLESTATE.has_white)
        {
            available4blacks++;
        }
        if (H01 != HOLESTATE.has_white && H10 != HOLESTATE.has_white)
        {
            available4blacks++;
        }
        if (H21 != HOLESTATE.has_white && H12 != HOLESTATE.has_white)
        {
            available4blacks++;
        }
    }
Пример #22
0
 bool?checkNear(Pentago_GameBoard gb, int whiteAlmost, int blackAlmost)
 {
     if (whiteAlmost >= 1 && gb.get_player_turn() == IA_PIECES_WHITES)
     {
         return(IA_PIECES_WHITES);
     }
     if (blackAlmost >= 1 && gb.get_player_turn() == IA_PIECES_BLACKS)
     {
         return(IA_PIECES_BLACKS);
     }
     return(null);
 }
Пример #23
0
    static public void testPerformance(int numOfBorads, int numpieces, int depth, MINMAX[] toTest)
    {
        Pentago_GameBoard[] testBoards = new Pentago_GameBoard[numOfBorads];
        String filename_compareP       = "CompareMinmaxsWithEqualPieces/comp_D" + depth.ToString();

        add2File(filename_compareP, numpieces.ToString(), false);

        if (numpieces % 2 == 0)
        {
            for (int i = 0; i < numOfBorads; i++)
            {
                GenerateRandomBoard rndBoard = new GenerateRandomBoard(numpieces / 2, true);
                rndBoard.generateNewBoard();
                testBoards[i] = rndBoard.Pentago_gb;
            }
        }
        else
        {
            for (int i = 0; i < numOfBorads; i++)
            {
                GenerateRandomBoard rndBoard = new GenerateRandomBoard((numpieces + 1) / 2, false);
                rndBoard.generateNewBoard();
                testBoards[i] = rndBoard.Pentago_gb;
            }
        }

        for (int i = 0; i < toTest.Length; ++i)
        {
            if (numpieces % 2 == 0)
            {
                ((Pentago_Rules)toTest[i].rules).IA_PIECES = Pentago_Rules.IA_PIECES_WHITES;
            }
            else
            {
                ((Pentago_Rules)toTest[i].rules).IA_PIECES = Pentago_Rules.IA_PIECES_BLACKS;
            }

            long   test    = Performance.PerformanceTimeMilisecs(toTest[i], testBoards);
            string timeStr = test.ToString();

            String vers            = toTest[i].version.ToString() + "_" + ((Pentago_Rules)toTest[i].rules).nsf.ToString() + "_" + ((Pentago_Rules)toTest[i].rules).remove_repeated_states_on_nextStates.ToString();
            String filename_depth  = "CheckComplexityPieces/" + vers + "_D" + depth.ToString();
            String filename_pieces = "CheckComplexityDepth/" + vers + "_P" + numpieces;

            add2File(filename_depth, numpieces.ToString() + ";" + timeStr);
            add2File(filename_pieces, depth.ToString() + ";" + timeStr);
            add2File(filename_compareP, ";" + timeStr, false);
        }
        add2File(filename_compareP, "");
    }
Пример #24
0
    public bool is_move_possible(Pentago_GameBoard gb)
    {
        if (gb.get_turn_state() == Pentago_GameBoard.turn_state_addpiece && gb.board[index] == Pentago_GameBoard.hole_state.is_empty)
        {
            return(true);
        }

        if (gb.get_turn_state() == Pentago_GameBoard.turn_state_rotate && square2rotate >= 0 && square2rotate < 4)
        {
            return(true);
        }

        return(false);
    }
Пример #25
0
    static void available_mulcross(HOLESTATE[] gb, int square, out int available4whites, out int available4blacks)
    {
        available4whites = 0;
        available4blacks = 0;

        HOLESTATE H11 = gb[Pentago_GameBoard.board_position_to_index(1, 1, square)];
        HOLESTATE H00 = gb[Pentago_GameBoard.board_position_to_index(0, 0, square)];
        HOLESTATE H02 = gb[Pentago_GameBoard.board_position_to_index(0, 2, square)];
        HOLESTATE H20 = gb[Pentago_GameBoard.board_position_to_index(2, 0, square)];
        HOLESTATE H22 = gb[Pentago_GameBoard.board_position_to_index(2, 2, square)];

        bool h11w = H11 != HOLESTATE.has_black;

        if (h11w && H00 != HOLESTATE.has_black)
        {
            available4whites++;
        }
        if (h11w && H02 != HOLESTATE.has_black)
        {
            available4whites++;
        }
        if (h11w && H20 != HOLESTATE.has_black)
        {
            available4whites++;
        }
        if (h11w && H22 != HOLESTATE.has_black)
        {
            available4whites++;
        }

        bool h11b = H11 != HOLESTATE.has_white;

        if (h11b && H00 != HOLESTATE.has_white)
        {
            available4blacks++;
        }
        if (h11b && H02 != HOLESTATE.has_white)
        {
            available4blacks++;
        }
        if (h11b && H20 != HOLESTATE.has_white)
        {
            available4blacks++;
        }
        if (h11b && H22 != HOLESTATE.has_white)
        {
            available4blacks++;
        }
    }
Пример #26
0
    /// <summary>
    /// This is the constructor for the class that generates random board
    /// </summary>
    /// <param name="num_pieces">Number of pieces that the last player will have</param>
    /// <param name="last_player_to_play">true last player = black; false last player = white</param>
    public GenerateRandomBoard(int num_pieces, bool last_player_to_play)
    {
        Pentago_gb = new Pentago_GameBoard();

        if (last_player_to_play)
        {
            player_turn_to_end = blacks_turn;
            number_of_plays    = num_pieces * 2;
        }
        else
        {
            player_turn_to_end = whites_turn;
            number_of_plays    = (num_pieces * 2) - 1;
        }
    }
Пример #27
0
    static void available_box2(HOLESTATE[] gb, int square, out int available4whites, out int available4blacks)
    {
        available4whites = 0;
        available4blacks = 0;

        HOLESTATE H00 = gb[Pentago_GameBoard.board_position_to_index(0, 0, square)];
        HOLESTATE H02 = gb[Pentago_GameBoard.board_position_to_index(0, 2, square)];
        HOLESTATE H20 = gb[Pentago_GameBoard.board_position_to_index(2, 0, square)];
        HOLESTATE H22 = gb[Pentago_GameBoard.board_position_to_index(2, 2, square)];
        HOLESTATE H10 = gb[Pentago_GameBoard.board_position_to_index(1, 0, square)];
        HOLESTATE H12 = gb[Pentago_GameBoard.board_position_to_index(1, 2, square)];
        HOLESTATE H01 = gb[Pentago_GameBoard.board_position_to_index(0, 1, square)];
        HOLESTATE H21 = gb[Pentago_GameBoard.board_position_to_index(2, 1, square)];

        if (H00 != HOLESTATE.has_black && H10 != HOLESTATE.has_black)
        {
            available4whites++;
        }
        if (H20 != HOLESTATE.has_black && H12 != HOLESTATE.has_black)
        {
            available4whites++;
        }
        if (H22 != HOLESTATE.has_black && H12 != HOLESTATE.has_black)
        {
            available4whites++;
        }
        if (H02 != HOLESTATE.has_black && H01 != HOLESTATE.has_black)
        {
            available4whites++;
        }

        if (H00 != HOLESTATE.has_white && H10 != HOLESTATE.has_white)
        {
            available4blacks++;
        }
        if (H20 != HOLESTATE.has_white && H12 != HOLESTATE.has_white)
        {
            available4blacks++;
        }
        if (H22 != HOLESTATE.has_white && H12 != HOLESTATE.has_white)
        {
            available4blacks++;
        }
        if (H02 != HOLESTATE.has_white && H01 != HOLESTATE.has_white)
        {
            available4blacks++;
        }
    }
Пример #28
0
    Pentago_Move[] getMoves(int[] squares)
    {
        Pentago_Move[] moves = new Pentago_Move[squares.Length * 9];
        int            i     = 0;

        foreach (int s in squares)
        {
            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    moves[i] = all_possible_place_piece_moves[Pentago_GameBoard.board_position_to_index(x, y, s)];
                    //moves[i] = new Pentago_Move(s, x, y);
                    i++;
                }
            }
        }

        return(moves);
    }
Пример #29
0
    /// <summary>
    /// Applies the play to the gameboard. Use apply_move2board instead unless you want to reutilize the Pentago_Move instance (usefull in aux methods to process stuff faster)
    /// </summary>
    /// <param name="gb"></param>
    /// <param name="turn">when turn state = placing a piece, tells what type piece will be placed</param>
    /// <param name="turnstate">whether player is placing a piece or rotating a square</param>
    /// <returns></returns>
    public HOLESTATE[] move(HOLESTATE[] gb, bool turn, bool turnstate)
    {
        HOLESTATE[] new_gb = (HOLESTATE[])gb.Clone();

        if (turnstate == Pentago_GameBoard.turn_state_addpiece)
        {
            new_gb[index]//Pentago_GameBoard.board_postion_to_index(hole2place_x, hole2place_y,square2place)]
                = turn == Pentago_GameBoard.blacks_turn ? HOLESTATE.has_black : HOLESTATE.has_white;
        }
        else
        {
            if (rotDir == rotate_clockwise)
            {
                for (int x = 0; x < 3; ++x)
                {
                    for (int y = 0; y < 3; ++y)
                    {
                        new_gb[Pentago_GameBoard.board_position_to_index(Math.Abs(2 - y), x, square2rotate)]
                            = gb[Pentago_GameBoard.board_position_to_index(x, y, square2rotate)];
                    }
                }
            }
            else
            {
                for (int x = 0; x < 3; ++x)
                {
                    for (int y = 0; y < 3; ++y)
                    {
                        new_gb[Pentago_GameBoard.board_position_to_index(y, Math.Abs(2 - x), square2rotate)]
                            = gb[Pentago_GameBoard.board_position_to_index(x, y, square2rotate)];
                    }
                }
            }
        }

        return(new_gb);
    }
Пример #30
0
 static void applyPrintMoves(Pentago_Move[] moves, Pentago_GameBoard board)
 {
     foreach (Pentago_Move move in moves)
     {
         if (board.get_player_turn() == Pentago_GameBoard.whites_turn)
         {
             Console.Write("White ");
         }
         else
         {
             Console.Write("Black ");
         }
         if (board.get_turn_state() == Pentago_GameBoard.turn_state_rotate)
         {
             Console.WriteLine("rotate");
         }
         else
         {
             Console.WriteLine("place");
         }
         move.apply_move2board(board);
         board.print_board();
     }
 }