Ejemplo n.º 1
0
        private Move GetMoveFromBoards(Board currentBoard, Board aiBoard)
        {
            Move returnMove = new Move();
            if (currentBoard.Equals(aiBoard))
            {
                returnMove.pieceColor = PieceColor.Empty;
                return returnMove;
            }

            PieceColor moveColor = (aiBoard.CurrentPlayer == PieceColor.White) ? PieceColor.Black: PieceColor.White;

            returnMove.pieceColor = moveColor;

            Board b = new Board(currentBoard);

            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    b.Copy(currentBoard);
                    if (b.GetColorAt(i, j) == PieceColor.Empty)
                    {
                        returnMove.xCoord = i;
                        returnMove.yCoord = j;

                        b.Copy(currentBoard);
                        b.PlacePieceAt(i, j, moveColor);
                        b.DoRotation(Rotation.LowerLeftAntiClockwise);
                        if (b.Equals(aiBoard))
                        {
                            returnMove.rotation = Rotation.LowerLeftAntiClockwise;
                            return returnMove;
                        }

                        b.Copy(currentBoard);
                        b.PlacePieceAt(i, j, moveColor);
                        b.DoRotation(Rotation.LowerLeftClockwise);
                        if (b.Equals(aiBoard))
                        {
                            returnMove.rotation = Rotation.LowerLeftClockwise;
                            return returnMove;
                        }

                        b.Copy(currentBoard);
                        b.PlacePieceAt(i, j, moveColor);
                        b.DoRotation(Rotation.LowerRightAntiClockwise);
                        if (b.Equals(aiBoard))
                        {
                            returnMove.rotation = Rotation.LowerRightAntiClockwise;
                            return returnMove;
                        }

                        b.Copy(currentBoard);
                        b.PlacePieceAt(i, j, moveColor);
                        b.DoRotation(Rotation.LowerRightClockwise);
                        if (b.Equals(aiBoard))
                        {
                            returnMove.rotation = Rotation.LowerRightClockwise;
                            return returnMove;
                        }

                        b.Copy(currentBoard);
                        b.PlacePieceAt(i, j, moveColor);
                        b.DoRotation(Rotation.UpperLeftAntiClockwise);
                        if (b.Equals(aiBoard))
                        {
                            returnMove.rotation = Rotation.UpperLeftAntiClockwise;
                            return returnMove;
                        }

                        b.Copy(currentBoard);
                        b.PlacePieceAt(i, j, moveColor);
                        b.DoRotation(Rotation.UpperLeftClockwise);
                        if (b.Equals(aiBoard))
                        {
                            returnMove.rotation = Rotation.UpperLeftClockwise;
                            return returnMove;
                        }

                        b.Copy(currentBoard);
                        b.PlacePieceAt(i, j, moveColor);
                        b.DoRotation(Rotation.UpperRightAntiClockwise);
                        if (b.Equals(aiBoard))
                        {
                            returnMove.rotation = Rotation.UpperRightAntiClockwise;
                            return returnMove;
                        }

                        b.Copy(currentBoard);
                        b.PlacePieceAt(i, j, moveColor);
                        b.DoRotation(Rotation.UpperRightClockwise);
                        if (b.Equals(aiBoard))
                        {
                            returnMove.rotation = Rotation.UpperRightClockwise;
                            return returnMove;
                        }
                    }
                }
            }
            // shouldn't ever get here
            Debug.Assert(false, "Bogus move \r\n" + masterBoard.ToString());
            return returnMove;
        }
Ejemplo n.º 2
0
        private void AnimateMove(Move move)
        {
            if (move.xCoord <= 2 &&
                move.yCoord <= 2)
            {
                LowerLeft.ShowDotPlacement(move.xCoord % 3, move.yCoord % 3, move.pieceColor);
            }
            else if (move.xCoord <= 2 &&
                move.yCoord > 2)
            {
                UpperLeft.ShowDotPlacement(move.xCoord % 3, move.yCoord % 3, move.pieceColor);
            }
            else if (move.xCoord > 2 &&
                move.yCoord <= 2)
            {
                LowerRight.ShowDotPlacement(move.xCoord % 3, move.yCoord % 3, move.pieceColor);
            }
            else if (move.xCoord > 2 &&
                move.yCoord > 2)
            {
                UpperRight.ShowDotPlacement(move.xCoord % 3, move.yCoord % 3, move.pieceColor);
            }

            // System.Threading.Thread.Sleep(1000);
            UpperLeft.ClearValue(Canvas.ZIndexProperty);
            UpperRight.ClearValue(Canvas.ZIndexProperty);
            LowerLeft.ClearValue(Canvas.ZIndexProperty);
            LowerRight.ClearValue(Canvas.ZIndexProperty);

            switch (move.rotation)
            {
                case Rotation.UpperLeftClockwise:
                    UpperLeft.SetValue(Canvas.ZIndexProperty, 9);
                    UpperLeft.ShowTwist(TwistDirection.Clockwise);
                    break;
                case Rotation.UpperLeftAntiClockwise:
                    UpperLeft.SetValue(Canvas.ZIndexProperty, 9);
                    UpperLeft.ShowTwist(TwistDirection.AntiClockwise);
                    break;
                case Rotation.UpperRightClockwise:
                    UpperRight.SetValue(Canvas.ZIndexProperty, 9);
                    UpperRight.ShowTwist(TwistDirection.Clockwise);
                    break;
                case Rotation.UpperRightAntiClockwise:
                    UpperRight.SetValue(Canvas.ZIndexProperty, 9);
                    UpperRight.ShowTwist(TwistDirection.AntiClockwise);
                    break;
                case Rotation.LowerLeftClockwise:
                    LowerLeft.SetValue(Canvas.ZIndexProperty, 9);
                    LowerLeft.ShowTwist(TwistDirection.Clockwise);
                    break;
                case Rotation.LowerLeftAntiClockwise:
                    LowerLeft.SetValue(Canvas.ZIndexProperty, 9);
                    LowerLeft.ShowTwist(TwistDirection.AntiClockwise);
                    break;
                case Rotation.LowerRightClockwise:
                    LowerRight.SetValue(Canvas.ZIndexProperty, 9);
                    LowerRight.ShowTwist(TwistDirection.Clockwise);
                    break;
                case Rotation.LowerRightAntiClockwise:
                   LowerRight.SetValue(Canvas.ZIndexProperty, 9);
                   LowerRight.ShowTwist(TwistDirection.AntiClockwise);
                   break;
                default:
                    break;
            }
        }