Example #1
0
        protected AIMove CopyBoardAndCreateMove(Move other, MoveType type)
        {
            IBoard currentBoard = new BoardPO(other.board);
            AIMove m            = CreateMove(type, id, currentBoard) as AIMove;

            m.CopyPossibleMoves(other);
            m.moveState = MoveState.SELECT;
            return(m as AIMove);
        }
Example #2
0
        protected List <AIMove> GetAllPossibleMoves()
        {
            List <AIMove> moves = new List <AIMove>();

            FindWinningPlayer();

            for (int k = 0; k < 2; k++)
            {
                //select player
                Vector2 srcPosition = board[id, k].Position;
                AIMove  mSelect     = CopyBoardAndCreateMove(this, type);
                // izracunati winnig player i kopirat ga u narednsa stanja,

                mSelect.SelectPlayer(srcPosition);

                // for all possible moves
                for (int i = 0; i < BoardPO.DIM; i++)
                {
                    for (int j = 0; j < BoardPO.DIM; j++)
                    {
                        if (mSelect.possibleMoves[i, j])
                        {
                            // make move
                            Vector2 dstPosition = new Vector2(i, j);
                            AIMove  mMove       = CopyBoardAndCreateMove(mSelect, type);
                            mMove.MovePlayer(dstPosition);

                            // for all possible builds after the move
                            for (int m = 0; m < BoardPO.DIM; m++)
                            {
                                for (int n = 0; n < BoardPO.DIM; n++)
                                {
                                    if (mMove.possibleMoves[m, n])
                                    {
                                        // build
                                        Vector2 buildPosition = new Vector2(m, n);
                                        AIMove  mBuild        = CopyBoardAndCreateMove(mMove, type);
                                        mBuild.Build(buildPosition);

                                        mBuild.move = new Vector2[] { srcPosition, dstPosition, buildPosition };

                                        mBuild.CopyWinningPlayer(this);
                                        if (mBuild.board[dstPosition].Height == Height.H3)
                                        {
                                            mBuild.isWinner = true;
                                        }
                                        else
                                        {
                                            mBuild.evaluationValue = mBuild.Evaluate(mBuild.move);
                                        }

                                        // change turn
                                        mBuild.board.ChangeTurn();
                                        mBuild.id = 1 - mBuild.id;

                                        /* mBuild.srcPosition = srcPosition;
                                         * mBuild.dstPosition = dstPosition;
                                         * mBuild.buildPosition = buildPosition;*/
                                        moves.Add(mBuild);
                                    }
                                }
                            }
                            mMove = null;
                        }
                    }
                }
                mSelect = null;
            }
            return(moves);
        }
Example #3
0
 private void CopyWinningPlayer(AIMove other)
 {
     winningPlayer.Position = other.winningPlayer.Position;
     winningPlayer.Id       = other.winningPlayer.Id;
     //Debug.Log("copy winning player me:" + winningPlayer.Position.x + winningPlayer.Position.y + "other" + other.winningPlayer.Position.x + other.winningPlayer.Position.y);
 }