Inheritance: UnitBehavior
示例#1
0
 public static Piece GetType(string s, ChessColor color)
 {
     Piece p;
     switch (s)
     {
         case "Bishop":
             p = new Bishop(color);
             break;
         case "King":
             p = new King(color);
             break;
         case "Knight":
             p = new Knight(color);
             break;
         case "Pawn":
             p = new Pawn(color);
             break;
         case "Queen":
             p = new Queen(color);
             break;
         case "Rook":
             p = new Rook(color);
             break;
         default:
             throw new Exception("Piece unknown : " + s);
     }
     return p;
 }
 public void Add(Knight knight)
 {
     if (knight != null) {
         _context.Knights.Add(knight);
         _context.SaveChanges();
     }
 }
示例#3
0
文件: Tests.cs 项目: dorotak/TDDKatas
        public void KnightReturnsNoPossibleMoves()
        {
            var board = new Board(3, 3);
            var initialCoordintates = new Vector(1, 1);
            var knight = new Knight(initialCoordintates, board);

            Assert.That(knight.GetPossibleMoves().Count(), Is.EqualTo(0));
        }
 private MessageType Remove(Knight knight)
 {
     if (knight != null) {
         _context.Knights.Remove(knight);
         _context.SaveChanges();
         return MessageType.Success;
     }
     return MessageType.Error;
 }
 public MessageType Update(Knight knight)
 {
     if (knight != null) {
         _context.Entry(knight).State = EntityState.Modified;
         _context.SaveChanges();
         return MessageType.Success;
     }
     return MessageType.Error;
 }
示例#6
0
        public override ChessPiece Clone(Board board)
        {
            var clone = new Knight(board, Color)
                {
                    MovingStrategy = MovingStrategy.Clone(board)
                };

            return clone;
        }
示例#7
0
文件: Tests.cs 项目: dorotak/TDDKatas
        public void KnightReturnsPossibleMoves()
        {
            var board = new Board(3, 3);
            var initialCoordintates = new Vector(0, 0);
            var knight = new Knight(initialCoordintates, board);

            var possibleMoves = knight.GetPossibleMoves();
            Assert.That(possibleMoves.First(x => x.Equals(AllowedMoves.RightUp)), Is.Not.Null);
            Assert.That(possibleMoves.First(x => x.Equals(AllowedMoves.UpRight)), Is.Not.Null);
        }
示例#8
0
        static void Main(string[] args)
        {
            Knight knight = new Knight();
            knight.fight();

            knight.SetWeapon(new Hammer());
            knight.fight();

            Console.ReadLine();
        }
        public void TestMethod1()
        {
            var king = new King();
            king.Fight();

            var knight = new Knight();
            knight.Fight();

            knight.SetWeaponBehavior(new AxeBehavior());
            knight.Fight();
        }
 public ActionResult Create(Knight knight)
 {
     if (ModelState.IsValid && knight != null)
     {
         KnightRepository.Add(knight);
         return RedirectToAction("Index");
     }
     ViewBag.Message = Messages.Error_Field_Check;
     ViewBag.Title = PersonResource.Title_CreateKnight;
     return View(knight);
 }
示例#11
0
文件: Tests.cs 项目: dorotak/TDDKatas
        public void PathFinderDoesNotFindThePathForSmallBoard(int boardSize,int x, int y)
        {
            var board = new Board(boardSize, boardSize);
            var initialCoordintates = new Vector(x, y);
            var knight = new Knight(initialCoordintates, board);

            var pathFinder = new PathFinder(knight);

            var result = pathFinder.FindPath();
            Assert.That(result, Is.EqualTo(false));
        }
示例#12
0
 void Start()
 {
     knight = knightGO.GetComponent<Knight>();
     style = new GUIStyle ();
     style.fontSize = 30;
     style.font = font;
     style.normal.textColor = Color.white;
     levelUpStyle = new GUIStyle ();
     levelUpStyle.fontSize = 60;
     levelUpStyle.font = font;
     levelUpStyle.normal.textColor = Color.white;
 }
示例#13
0
        public Character ReadClass(int archetype, string wrmc)
        {
            int choice;
            Character player;

            MyTTY.Show("The following " + wrmc + " are available to you:\n\n");

            switch (archetype)
            {
                case 1:
                    MyTTY.Show("1) Knight\n");
                    MyTTY.Show("2) Berserker\n");
                    break;

                case 2:
                    MyTTY.Show("1) Hunter\n");
                    MyTTY.Show("2) Assassin\n");
                    break;

                case 3:
                    MyTTY.Show("1) Sorcerer\n");
                    MyTTY.Show("2) Warlock\n");
                    break;

                case 4:
                    MyTTY.Show("1) Priest\n");
                    MyTTY.Show("2) Druid\n");
                    break;
            }

            choice = MyTTY.ReadIntLimit("\nEnter the number of your selection: ", 2);

            switch (archetype)
            {
                case 1:
                    if (choice < 2) player = new Knight(); else player = new Berserker();
                    break;
                case 2:
                    if (choice < 2) player = new Hunter(); else player = new Assassin();
                    break;
                case 3:
                    if (choice < 2) player = new Sorcerer(); else player = new Warlock();
                    break;
                case 4:
                    if (choice < 2) player = new Priest(); else player = new Druid();
                    break;
                default:
                    player = null;
            }

            return player;
        }
示例#14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PlayerChess"/> class.
        /// </summary>
        /// <param name="color">The piece color.</param>
        /// <param name="gameboard">The gameboard.</param>
        public PlayerChess(IPieceColor color, Gameboard gameboard)
            : base(color)
        {
            IPiece newPiece;
            int offset = 0;

            this.gameboard = gameboard;
            this.selectedPiece = null;

            if (color == IPieceColor.White)
            {
                offset = 7;
            }
            else if (color == IPieceColor.Black)
            {
                offset = 0;
            }

            for (int i = 0; i < 8; i++)
            {
                newPiece = new Pawn(color, gameboard, new Position(i, Math.Abs(offset - 1)));
                newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
                this.PieceList.Add(newPiece);
            }

            newPiece = new Rook(color, gameboard, new Position(0, offset));
            newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
            this.PieceList.Add(newPiece);
            newPiece = new Rook(color, gameboard, new Position(7, offset));
            newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
            this.PieceList.Add(newPiece);
            newPiece = new Knight(color, gameboard, new Position(1, offset));
            newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
            this.PieceList.Add(newPiece);
            newPiece = new Knight(color, gameboard, new Position(6, offset));
            newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
            this.PieceList.Add(newPiece);
            newPiece = new Bishop(color, gameboard, new Position(2, offset));
            newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
            this.PieceList.Add(newPiece);
            newPiece = new Bishop(color, gameboard, new Position(5, offset));
            newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
            this.PieceList.Add(newPiece);
            newPiece = new Queen(color, gameboard, new Position(3, offset));
            newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
            this.PieceList.Add(newPiece);
            newPiece = new King(color, gameboard, new Position(4, offset));
            newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
            this.PieceList.Add(newPiece);
            this.King = newPiece;
        }
        public static IJedi CreateJedi(string name)
        {
            char type = name[0];
            Jedi jedi;

            switch (type)
            {
                case 'm': jedi = new Master(name); break;
                case 'k': jedi = new Knight(name); break;
                case 'p': jedi = new Padawan(name); break;
                default: jedi = null; break;
            }

            return jedi;
        }
示例#16
0
 void Start()
 {
     knightObject = GameObject.FindGameObjectWithTag ("Player");
     if (knightObject != null) {
         target = knightObject.transform;
         knight = knightObject.GetComponent<Knight> ();
     }
     AnimationEvent hitEvent = new AnimationEvent();
     hitEvent.functionName = "SetIdle";
     hitEvent.time = animation.GetClip("gethit").length;
     animation.GetClip("gethit").AddEvent(hitEvent);
     AnimationEvent attackEvent = new AnimationEvent();
     attackEvent.functionName = "SetIdle";
     attackEvent.time = animation.GetClip("attack").length;
     animation.GetClip("attack").AddEvent(attackEvent);
 }
示例#17
0
        public void TestFromFenValid()
        {
            const string FEN_STRING = "pQ4N1/3k3R/1r4n1/KbBbBppP/8/8/q7/7n";
            FENSerializer ser = new FENSerializer();
            Board expected = new Board(null);
            Board actual;

            // Setup
            expected['8', 'A'] = new Pawn('b');
            expected['8', 'B'] = new Queen('w');
            expected['8', 'G'] = new Knight('w');

            expected['7', 'D'] = new King('b');
            expected['7', 'H'] = new Rook('w');

            expected['6', 'B'] = new Rook('b');
            expected['6', 'G'] = new Knight('b');

            expected['5', 'A'] = new King('w');
            expected['5', 'B'] = new Bishop('b');
            expected['5', 'C'] = new Bishop('w');
            expected['5', 'D'] = new Bishop('b');
            expected['5', 'E'] = new Bishop('w');
            expected['5', 'F'] = new Pawn('b');
            expected['5', 'G'] = new Pawn('b');
            expected['5', 'H'] = new Pawn('w');

            expected['2', 'A'] = new Queen('b');
            expected['1', 'H'] = new Knight('b');

            // Act
            actual = ser.Deserialize(FEN_STRING);

            // Test
            for (int file = 0; file < Board.NUM_FILES; file++)
            {
                for (int row = 0; row < Board.NUM_ROWS; row++)
                {
                    Piece expectedPiece = expected[row, file];
                    Piece actualPiece = actual[row, file];
                    bool areEqual = Piece.AreEqual(expectedPiece, actualPiece);

                    Assert.IsTrue(areEqual);
                }
            }
        }
示例#18
0
        public void placeBlackFigures()
        {
            Figure[] pawns = new Figure[8];
            Figure[] otherFigures = new Figure[8];
            char currentChar = 'A';
            char charPositionPawn = 'A';
            for (int i = 0; i < 8; i++)
            {

                pawns[i] = new Pawn(charPositionPawn, 2, false);
                charPositionPawn++;


                if ((currentChar == 'A') || (currentChar == 'H'))
                {
                    otherFigures[i] = new Rook(currentChar, 1, false);
                }
                else if ((currentChar == 'B') || (currentChar == 'G'))
                {
                    otherFigures[i] = new Knight(currentChar, 1, false);
                }
                else if ((currentChar == 'C') || (currentChar == 'F'))
                {
                    otherFigures[i] = new Bishop(currentChar, 1, false);
                }
                else if (currentChar == 'E')
                {
                    otherFigures[i] = new King(currentChar, 1, false);
                }
                else
                {
                    otherFigures[i] = new Queen(currentChar, 1, false);

                }

                currentChar++;
            }
            for (int i = 0; i < 8; i++)
            {
                placeFigure(pawns[i]);
                placeFigure(otherFigures[i]);
            }


        }
示例#19
0
文件: Tests.cs 项目: dorotak/TDDKatas
        public void TheKnightCanDoOnlyTwoMovesFromTheCorner()
        {
            var board = new Board(8, 8);
            var initialCoordintates = new Vector(0, 0);

            var knight = new Knight(initialCoordintates, board);
            knight.Move(AllowedMoves.UpLeft);
            Assert.That(knight.IsOnTheBoard, Is.EqualTo(false));

            knight.Reset();
            knight.Move(AllowedMoves.UpRight);
            Assert.That(knight.IsOnTheBoard, Is.EqualTo(true));

            knight.Reset();
            knight.Move(AllowedMoves.DownLeft);
            Assert.That(knight.IsOnTheBoard, Is.EqualTo(false));

            knight.Reset();
            knight.Move(AllowedMoves.DownRight);
            Assert.That(knight.IsOnTheBoard, Is.EqualTo(false));

            knight.Reset();
            knight.Move(AllowedMoves.LeftUp);
            Assert.That(knight.IsOnTheBoard, Is.EqualTo(false));

            knight.Reset();
            knight.Move(AllowedMoves.LeftDown);
            Assert.That(knight.IsOnTheBoard, Is.EqualTo(false));

            knight.Reset();
            knight.Move(AllowedMoves.RightDown);
            Assert.That(knight.IsOnTheBoard, Is.EqualTo(false));

            knight.Reset();
            knight.Move(AllowedMoves.RightUp);
            Assert.That(knight.IsOnTheBoard, Is.EqualTo(true));
        }
示例#20
0
 public abstract void VisitKnight(Knight knight);
示例#21
0
 public void Awake()
 {
     knight           = knight_inst;
     worldTiles       = worldTiles_inst;
     detonationHolder = detonationHolder_inst;
 }
示例#22
0
    static void Main()
    {
        // Change console's output encoding to UTF-8. It's a good practice for all future developments.
        Console.OutputEncoding = System.Text.Encoding.UTF8;
        // Create an object of class Knight and call it "kenobi".
        Knight kenobi = new Knight();

        Console.WriteLine("Wellcome to Knight's Tour game");
        Console.Write("Choose a moving mode (press \"A\" for automatic mode, or \"M\" for manual mode): ");
        // Create an element of enumeration ConsoleKey and assign it to a key, pressed by a user.
        ConsoleKey keyPressed = Console.ReadKey(true).Key;

        Console.WriteLine();

        // Loop asking a user to choose a mode by pressing "A" or "M'.
        while (keyPressed != ConsoleKey.A && keyPressed != ConsoleKey.M)
        {
            Console.WriteLine("You should press \"A\" or \"M\".");
            Console.Write("Choose a moving mode (press \"A\" for automatic mode, or \"M\" for manual mode): ");
            // ReadKey method of a Console class get a key pressed by a user. "true" parameter tells it to print a key a user pressed.
            keyPressed = Console.ReadKey(true).Key;
            Console.WriteLine();
        }

        // Store "true" in "autoMode" variable if user have pressed "A" and store "false" otherwise.
        bool autoMode = keyPressed == ConsoleKey.A
            ? true
            : false;

        // Create a variable to later determine whether to choose knight's start position.
        bool chooseStartPosition = false;

        // Manual mode explicitly means choosing start positions, but for auto mode we ask user whether he/she wants to use it.
        if (autoMode)
        {
            keyPressed = ConsoleKey.Spacebar;
            Console.Write("Do you want to choose start position\n"
                          + "(Press \"C\" to choose start position or \"A\" to make 64 tours from every possible start position): ");
            keyPressed = Console.ReadKey(true).Key;
            Console.WriteLine();


            // Loop until user presses "A" or "C".
            while (keyPressed != ConsoleKey.C && keyPressed != ConsoleKey.A)
            {
                Console.WriteLine("You should press \"C\" or \"A\".");
                Console.Write("Do you want to choose start position\n"
                              + "(Press\"C\" to choose start position or \"A\" to make 64 tours from every possible start position): ");
                keyPressed = Console.ReadKey(true).Key;
                Console.WriteLine();
            }

            // If user pressed "C" then assign "true" to "chooseStartPosition".
            if (keyPressed == ConsoleKey.C)
            {
                chooseStartPosition = true;
            }
        }

        // For manual mode and in case of user selected to choose knight's start position in auto mode, let him/her do so.
        if (!autoMode || chooseStartPosition)
        {
            // Create two local variables and store there initial row and column numbers entered by a user.
            // I use 0 to 7 numbers instead of 1 to 8 for development simplicity.
            Console.Write($"Choose a start position row (type a number from 0 to {kenobi.GetBoardRowsNumber() - 1} and press Enter): ");
            int rowToSet = int.Parse(Console.ReadLine());

            while (rowToSet < 0 || rowToSet >= kenobi.GetBoardRowsNumber())
            {
                Console.WriteLine($"You should type an integer from \"0\" to \"{kenobi.GetBoardRowsNumber() - 1}\".");
                Console.Write($"Choose a start position row (type a number from 0 to {kenobi.GetBoardRowsNumber() - 1} and press Enter): ");
                rowToSet = int.Parse(Console.ReadLine());
            }

            Console.Write($"Choose a start position column (type a number from 0 to {kenobi.GetBoardColumnsNumber() - 1} and press Enter): ");
            int columnToSet = int.Parse(Console.ReadLine());

            while (columnToSet < 0 || columnToSet >= kenobi.GetBoardColumnsNumber())
            {
                Console.WriteLine($"You should type an integer from \"0\" to \"{kenobi.GetBoardColumnsNumber() - 1}\".");
                Console.Write($"Choose a start position column (type a number from 0 to {kenobi.GetBoardColumnsNumber() - 1} and press Enter): ");
                columnToSet = int.Parse(Console.ReadLine());
            }

            // Set current poisition row and column to values entered by a user.
            kenobi.CurrentPositionRow    = rowToSet;
            kenobi.CurrentPositionColumn = columnToSet;
            // As soon as knight already stays on the point, call apropriate method to mark it as visited.
            kenobi.MarkPointAsVisited(rowToSet, columnToSet);
        }

        // All the logic for manual mode.
        if (!autoMode)
        {
            // Here we print and reprint all the information, including table every time user presses a buttom.
            // If the pressed button corresponds to a possible move, the move is made. Current information is reprinted otherwise.
            while (kenobi.PossibleMoveExists())
            {
                Console.Clear();
                Console.WriteLine("Knight's Tour");
                Console.Write($"Moving mode: manual. Current position: {kenobi.CurrentPositionRow}:{kenobi.CurrentPositionColumn}. ");
                Console.WriteLine($"Moves made: {kenobi.NumberOfMovesMade}");
                kenobi.PrintAllKnightsMoves();
                kenobi.PrintBoard();
                Console.Write("Press a move number: ");
                // Set initial value of "moveNumber" to 100. There is no move with such a number.
                int moveNumber = 100;
                // Read a key pressed by a user to "keyPressed" element of enumeration "ConsoleKey".
                keyPressed = Console.ReadKey(true).Key;

                // If user presses a number from 0 to 7, assign it to "moveNumber". In all other cases - leave previous value there.
                switch (keyPressed)
                {
                case ConsoleKey.D0:
                case ConsoleKey.NumPad0:
                    moveNumber = 0;
                    break;

                case ConsoleKey.D1:
                case ConsoleKey.NumPad1:
                    moveNumber = 1;
                    break;

                case ConsoleKey.D2:
                case ConsoleKey.NumPad2:
                    moveNumber = 2;
                    break;

                case ConsoleKey.D3:
                case ConsoleKey.NumPad3:
                    moveNumber = 3;
                    break;

                case ConsoleKey.D4:
                case ConsoleKey.NumPad4:
                    moveNumber = 4;
                    break;

                case ConsoleKey.D5:
                case ConsoleKey.NumPad5:
                    moveNumber = 5;
                    break;

                case ConsoleKey.D6:
                case ConsoleKey.NumPad6:
                    moveNumber = 6;
                    break;

                case ConsoleKey.D7:
                case ConsoleKey.NumPad7:
                    moveNumber = 7;
                    break;

                default:
                    break;
                }

                // If user entered a move from 0 to 7 inclusive and this move is possible - make it.
                if (moveNumber >= 0 &&
                    moveNumber <= 7 &&
                    kenobi.MoveIsPossible(moveNumber, kenobi.CurrentPositionRow, kenobi.CurrentPositionColumn))
                {
                    kenobi.MakeMove(moveNumber);
                }

                // End of "while" loop.
            }

            // This method deletes all previous information printed in console window.
            Console.Clear();
            // Print game statistics using "PrintResultsOnePosition()" method of class "Knight".
            kenobi.PrintResultsOnePosition();
            Console.Write("Press any key to exit.");
            // This is used to let user see previus message before console window is closed.
            // After user presses any pressed the app terminates.
            Console.ReadKey();

            // End of "if (!autoMode)".
        }

        // All the logic for automatic mode.
        if (autoMode)
        {
            // Assign "Spacebar" key to "keyPressed" as soon as app wouldn't use it for any command.
            keyPressed = ConsoleKey.Spacebar;
            // Ask user whether he/she want to use accessibility table and if so, assign "true" to "kenobi.UseAccessibilityTable".
            Console.Write("Do you want to use accessibility table (press \"Y\" for yes, or \"N\" for no): ");
            keyPressed = Console.ReadKey(true).Key;

            while (keyPressed != ConsoleKey.Y && keyPressed != ConsoleKey.N)
            {
                Console.WriteLine("You should press \"Y\" or \"N\".");
                Console.Write("Do you want to use accessibility table (press \"Y\" for yes, or \"N\" for no): ");
                keyPressed = Console.ReadKey(true).Key;
            }

            if (keyPressed == ConsoleKey.Y)
            {
                kenobi.UseAccessibilityTable = true;
            }

            Console.WriteLine();

            if (kenobi.UseAccessibilityTable)
            {
                // Assign "Spacebar" key to "keyPressed" as soon as app wouldn't use it for any command.
                keyPressed = ConsoleKey.Spacebar;
                // Ask user whether he/she want to use lookup and if so, assign "true" to "kenobi.UseLookup".
                Console.Write("Do you want to use lookup (press \"Y\" for yes, or \"N\" for no): ");
                keyPressed = Console.ReadKey(true).Key;

                while (keyPressed != ConsoleKey.Y && keyPressed != ConsoleKey.N)
                {
                    Console.WriteLine("You should press \"Y\" or \"N\".");
                    Console.Write("Do you want to use lookup (press \"Y\" for yes, or \"N\" for no): ");
                    keyPressed = Console.ReadKey(true).Key;
                }

                if (keyPressed == ConsoleKey.Y)
                {
                    kenobi.UseLookup = true;
                }
            }

            // If user decided to choose a start position, they are already assigned previously so app start moving a knight.
            // The moves logic is different depending on whether users has chosen to use accessibility table and lookup.
            if (chooseStartPosition)
            {
                while (kenobi.PossibleMoveExists())
                {
                    for (int moveNumber = 0; moveNumber <= 7; ++moveNumber)
                    {
                        if (kenobi.MoveIsPossible(moveNumber, kenobi.CurrentPositionRow, kenobi.CurrentPositionColumn))
                        {
                            kenobi.MakeMove(moveNumber);
                            // We force "for" loop to breake to start counting from 0 every time a move made.
                            // This allows us to make a move with lowest number possible every time.
                            break;
                        }
                    }
                }

                // After all moves are made, the console screen is cleared and game statistics is printed.
                Console.Clear();
                kenobi.PrintResultsOnePosition();
                Console.Write("Press any key to exit.");
                Console.ReadKey();
            }

            // Here we impelement all the logic for a case where knight makes 64 different tours.
            // 1st tour is made from 0:0 start position and the last one is made from 63:63 start position.
            if (!chooseStartPosition)
            {
                // These varuables is used to store the number of successful and unsuccessful tours made by a knight.
                // Their sum always eqauls to 64 at the end of a game.
                int successfulTours   = 0;
                int unseccessfulTours = 0;

                // Two "for" loops used to cover all possible start positions.
                for (int positionX = 0; positionX <= 7; ++positionX)
                {
                    for (int positionY = 0; positionY <= 7; ++positionY)
                    {
                        // "ResetBoard()" method of class "Knight" resets all board properties and fields to their initial values
                        // and sets knight's current row and column positions to values of "positionX" and "positionY" correspondingly.
                        kenobi.ResetBoard(positionX, positionY);

                        // If accessibility table is used possible moves made until there is at least one possible move.
                        if (!kenobi.UseAccessibilityTable)
                        {
                            while (kenobi.PossibleMoveExists())
                            {
                                for (int moveNumber = 0; moveNumber <= 7; ++moveNumber)
                                {
                                    if (kenobi.MoveIsPossible(moveNumber, kenobi.CurrentPositionRow, kenobi.CurrentPositionColumn))
                                    {
                                        kenobi.MakeMove(moveNumber);
                                        // We force "for" loop to breake to start counting from 0 every time a move made.
                                        // This allows us to make a move with lowest number possible every time.
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            // For cases when accessibility table or/and lookup is used, the logic is implemented within "MakeMove()".
                            while (kenobi.PossibleMoveExists())
                            {
                                kenobi.MakeMove();
                            }
                        }

                        // Count successful and unsuccessful tours for every tour made.
                        if (kenobi.NumberOfMovesMade == 63)
                        {
                            ++successfulTours;
                        }
                        else
                        {
                            ++unseccessfulTours;
                        }
                    }
                }

                // After all moves are made, the console screen is cleared and game statistics is printed.
                Console.Clear();
                kenobi.PrintResultsAllPositions(successfulTours, unseccessfulTours);
                Console.Write("Press any key to exit.");
                Console.ReadKey();
            }
        }
    }
示例#23
0
        public Board()
        {
            for (int Row = 0; Row < 8; Row++)
            {
                for (int Col = 0; Col < 16; Col++)
                {
                    board[Row, Col] = null;
                }
            }

            // black inner pawns
            for (int Row = 0; Row < 8; Row++)
            {
                board[Row, 10] = new InnerPawn('b');
            }
            // black outer pawns
            for (int Row = 0; Row < 8; Row++)
            {
                board[Row, 13] = new OuterPawn('b');
            }

            //black pieces
            board[0, 11] = new Rook('b');
            board[0, 12] = new Rook('b');
            board[7, 11] = new Rook('b');
            board[7, 12] = new Rook('b');

            board[1, 11] = new Knight('b');
            board[1, 12] = new Knight('b');
            board[6, 11] = new Knight('b');
            board[6, 12] = new Knight('b');

            board[2, 11] = new Bishop('b');
            board[2, 12] = new Bishop('b');
            board[5, 11] = new Bishop('b');
            board[5, 12] = new Bishop('b');

            board[3, 12] = new Queen('b');
            board[4, 12] = new Queen('b');

            board[3, 11] = new General('b');
            board[4, 11] = new King('b');

            // white inner pawns
            for (int Row = 0; Row < 8; Row++)
            {
                board[Row, 5] = new InnerPawn('w');
            }
            // white outer pawns
            for (int Row = 0; Row < 8; Row++)
            {
                board[Row, 2] = new OuterPawn('w');
            }
            //white pieces
            board[0, 3] = new Rook('w');
            board[0, 4] = new Rook('w');
            board[7, 3] = new Rook('w');
            board[7, 4] = new Rook('w');

            board[1, 3] = new Knight('w');
            board[1, 4] = new Knight('w');
            board[6, 3] = new Knight('w');
            board[6, 4] = new Knight('w');

            board[2, 3] = new Bishop('w');
            board[2, 4] = new Bishop('w');
            board[5, 3] = new Bishop('w');
            board[5, 4] = new Bishop('w');

            board[3, 3] = new Queen('w');
            board[4, 3] = new Queen('w');

            board[3, 4] = new General('w');
            board[4, 4] = new King('w');
        }
示例#24
0
        public bool DoubleCheckedFen(int[] board, bool sideToMove, int[] kingSquare)
        {
            var possibleDoubleCheck = false;

            #region white side

            if (sideToMove == Definitions.White)
            {
                var whiteKnight      = new Knight(board, kingSquare[1], Definitions.White);
                var listOfWhiteMoves = whiteKnight.MoveGeneration();

                foreach (var square in listOfWhiteMoves)
                {
                    if (board[square] == Definitions.BlackKnight)
                    {
                        possibleDoubleCheck = true;
                        break;
                    }
                }

                if (!possibleDoubleCheck)
                {
                    return(false);
                }

                var whiteBishop = new Bishop(board, kingSquare[1], Definitions.White);
                listOfWhiteMoves = whiteBishop.MoveGeneration();
                foreach (var square in listOfWhiteMoves)
                {
                    if (board[square] == Definitions.BlackBishop)
                    {
                        return(true);
                    }
                }


                var whiteRook = new Rook(board, kingSquare[1], Definitions.White);
                listOfWhiteMoves = whiteRook.MoveGeneration();
                foreach (var square in listOfWhiteMoves)
                {
                    if (board[square] == Definitions.BlackRook)
                    {
                        return(true);
                    }
                }
            }
            #endregion

            #region black side

            else
            {
                var blackKnight      = new Knight(board, kingSquare[0], Definitions.Black);
                var listOfBlackMoves = blackKnight.MoveGeneration();

                foreach (var square in listOfBlackMoves)
                {
                    if (board[square] == Definitions.WhiteKnight)
                    {
                        possibleDoubleCheck = true;
                        break;
                    }
                }

                if (!possibleDoubleCheck)
                {
                    return(false);
                }

                var blackBishop = new Bishop(board, kingSquare[0], Definitions.Black);
                listOfBlackMoves = blackBishop.MoveGeneration();
                foreach (var square in listOfBlackMoves)
                {
                    if (board[square] == Definitions.WhiteBishop)
                    {
                        return(true);
                    }
                }

                var blackRook = new Rook(board, kingSquare[0], Definitions.Black);
                listOfBlackMoves = blackRook.MoveGeneration();
                foreach (var square in listOfBlackMoves)
                {
                    if (board[square] == Definitions.WhiteRook)
                    {
                        return(true);
                    }
                }
            }

            #endregion

            return(false);
        }
示例#25
0
 public KnightTests()
 {
     _sut = new Knight(Color.White);
 }
示例#26
0
        static void Main(string[] args)
        {
            Rider knight = new Knight(10, 5);

            Rider elephant = new Elephant(20, 3);

            Soldier archer = new Archer(5, 4);

            Soldier templar = new Templar(9, 5);

            List <string>  L  = new List <string>();
            List <Soldier> L2 = new List <Soldier>();

            L.Add("knight");
            L.Add("elephant");
            L.Add("archer");
            L.Add("templar");

            L2.Add(knight);
            L2.Add(elephant);
            L2.Add(archer);
            L2.Add(templar);
            Console.WriteLine("soldier type            power            rating");
            for (int i = 0; i < 4; i++)
            {
                Console.WriteLine("{0,-25}{1,-20}{2}", L[i], L2[i].GetPower(), L2[i].GetRating());
            }



            List <Soldier> Army1 = new List <Soldier>();
            List <Soldier> Army2 = new List <Soldier>();

            List <int> Ar1 = new List <int>();
            List <int> Ar2 = new List <int>();



            Console.WriteLine("Enter the number of soldier-types in Army1: ");
            int type1 = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter soldier-types of Army1 and their number, respectively: knight, templar, archer, elephant");
            for (int i = 0; i < type1; i++)
            {
                string Fighter1    = Console.ReadLine();
                int    SoldierNum1 = int.Parse(Console.ReadLine());

                Ar1.Add(SoldierNum1);
                switch (Fighter1)
                {
                case "knight": Army1.Add(knight); break;

                case "archer": Army1.Add(archer); break;

                case "templar": Army1.Add(templar); break;

                case "elephant": Army1.Add(elephant); break;

                default:
                    break;
                }
            }
            Console.WriteLine("Enter the number of soldier-types in Army2: ");
            int type2 = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter soldier-types of Army2 and their number, respectively: knight, templar, archer, elephant");

            for (int i = 0; i < type2; i++)
            {
                String Fighter2    = Console.ReadLine();
                int    SoldierNum2 = int.Parse(Console.ReadLine());
                Ar2.Add(SoldierNum2);
                switch (Fighter2)
                {
                case "knight": Army2.Add(knight); break;

                case "archer": Army2.Add(archer); break;

                case "templar": Army2.Add(templar); break;

                case "elephant": Army2.Add(elephant); break;

                default:
                    break;
                }
            }



            Program p = new Program();

            p.Fight(Army1, Army2, Ar1, Ar2);



            Console.ReadKey();
        }
示例#27
0
 public override bool DealWithKnight(Knight knight)
 {
     knight.animator.SetTrigger("attack");
     money -= knight.AttackPoints;
     return(false);
 }
示例#28
0
            /* Numbers of chessmen are: 0 - King, 1 - Queen, 2 - Bishop, 3 - Knight, 4 - Tower,
             * 5 - Pawn of Queen, 6 - Pawn of Bishop, 7 - Pawn of Knight, 8 - Pawn of Tower.
             * Numbers of players are: 0 - Yellow, 1 - Red, 2 - Blue, 3 - Black.
             * Number of arrangement - numberOfArrangement. */
            public Chessman CreateNewChessman(string playersColor, string chessmanName, Chessboard chessboard)
            {
                int indexOfPlayer = -1;
                int indexOfChessman = -1;
                ChessmenParameters chessmanParam = new ChessmenParameters();
                Chessman result;
                //gets number of player
                switch (playersColor)
                {
                    case "Yellow": indexOfPlayer = 0;
                        break;
                    case "Red": indexOfPlayer = 1;
                        break;
                    case "Blue": indexOfPlayer = 2;
                        break;
                    case "Black": indexOfPlayer = 3;
                        break;
                    default:
                        {
                            MessageBox.Show("Внутренняя ошибка, невозможно выполнить действие");
                            return null;
                        }
                }

                //gets number of chessman
                switch (chessmanName)
                {
                    case "King": indexOfChessman = 0;
                        break;
                    case "Queen": indexOfChessman = 1;
                        break;
                    case "Bishop": indexOfChessman = 2;
                        break;
                    case "Knight": indexOfChessman = 3;
                        break;
                    case "Tower": indexOfChessman = 4;
                        break;
                    case "PawnOfQueen": indexOfChessman = 5;
                        chessmanName = "Pawn of Queen";
                        break;
                    case "PawnOfBishop": indexOfChessman = 6;
                        chessmanName = "Pawn of Bishop";
                        break;
                    case "PawnOfKnight": indexOfChessman = 7;
                        chessmanName = "Pawn of Knight";
                        break;
                    case "PawnOfTower": indexOfChessman = 8;
                        chessmanName = "Pawn of Tower";
                        break;
                    default:
                        {
                            MessageBox.Show("Внутренняя ошибка, невозможно выполнить действие");
                            return null;
                        }
                }

                //set parameters
                chessmanParam.horizontal = positionOfChessmen[numberOfArrangement, indexOfPlayer, indexOfChessman, 1];
                chessmanParam.vertical = positionOfChessmen[numberOfArrangement, indexOfPlayer, indexOfChessman, 0];
                chessmanParam.ruNameNominative = GetNominativeRu(indexOfPlayer, indexOfChessman);
                chessmanParam.engName = playersColor + ' ' + chessmanName;
                chessmanParam.chessmanBitmap = chessmanBitmap[indexOfPlayer, indexOfChessman];
                chessmanParam.ruNameAccusative = GetAccusativeRu(indexOfPlayer, indexOfChessman);
                chessmanParam.kindOfChessman = (ChessmenNames)indexOfChessman;
                chessmanParam.player = (Players)indexOfPlayer;
                chessmanParam.ruAttack = GetAttackRu(indexOfChessman);
                chessmanParam.ruMove = GetMoveRu(indexOfChessman);
                switch (indexOfChessman)
                {
                    case 0: result = new King(chessmanParam, chessboard);
                        break;
                    case 1: result = new Queen(chessmanParam, chessboard);
                        break;
                    case 2: result = new Bishop(chessmanParam, chessboard);
                        break;
                    case 3: result = new Knight(chessmanParam, chessboard);
                        break;
                    case 4: result = new Tower(chessmanParam, chessboard);
                        break;
                    case 5: result = GetNewCorrectPawn(chessmanParam, chessboard);
                        break;
                    case 6: result = GetNewCorrectPawn(chessmanParam, chessboard);
                        break;
                    case 7: result = GetNewCorrectPawn(chessmanParam, chessboard);
                        break;
                    case 8: result = GetNewCorrectPawn(chessmanParam, chessboard);
                        break;
                    default:
                        {
                            result = null;
                            break;
                        }
                }
                return result;
            }
示例#29
0
文件: Tests.cs 项目: dorotak/TDDKatas
        public void TheKnightMovesWithinTheBoard()
        {
            var board = new Board(8, 8);
            var initialCoordintates = new Vector(4, 4);

            var knight = new Knight(initialCoordintates, board);
            knight.Move(AllowedMoves.UpLeft);
            Assert.That(knight.CurrentPosition, Is.EqualTo(new Vector(3, 6)));
            Assert.That(knight.IsOnTheBoard, Is.EqualTo(true));

            knight.Reset();
            knight.Move(AllowedMoves.UpRight);
            Assert.That(knight.CurrentPosition, Is.EqualTo(new Vector(5, 6)));
            Assert.That(knight.IsOnTheBoard, Is.EqualTo(true));

            knight.Reset();
            knight.Move(AllowedMoves.DownLeft);
            Assert.That(knight.CurrentPosition, Is.EqualTo(new Vector(3, 2)));
            Assert.That(knight.IsOnTheBoard, Is.EqualTo(true));

            knight.Reset();
            knight.Move(AllowedMoves.DownRight);
            Assert.That(knight.CurrentPosition, Is.EqualTo(new Vector(5, 2)));
            Assert.That(knight.IsOnTheBoard, Is.EqualTo(true));

            knight.Reset();
            knight.Move(AllowedMoves.LeftUp);
            Assert.That(knight.CurrentPosition, Is.EqualTo(new Vector(2, 5)));
            Assert.That(knight.IsOnTheBoard, Is.EqualTo(true));

            knight.Reset();
            knight.Move(AllowedMoves.LeftDown);
            Assert.That(knight.CurrentPosition, Is.EqualTo(new Vector(2, 3)));
            Assert.That(knight.IsOnTheBoard, Is.EqualTo(true));

            knight.Reset();
            knight.Move(AllowedMoves.RightDown);
            Assert.That(knight.CurrentPosition, Is.EqualTo(new Vector(6, 3)));
            Assert.That(knight.IsOnTheBoard, Is.EqualTo(true));

            knight.Reset();
            knight.Move(AllowedMoves.RightUp);
            Assert.That(knight.CurrentPosition, Is.EqualTo(new Vector(6, 5)));
            Assert.That(knight.IsOnTheBoard, Is.EqualTo(true));
        }
示例#30
0
        public GameObject()
        {
            for (sbyte i = 1; i <= 8; i++)
              {
            Pawn p1 = new Pawn(this, i, 7, Color.black);
            this.blacks.Add(p1);

            Pawn wp1 = new Pawn(this, i, 2, Color.white);
            this.whites.Add(wp1);
              }

              Bishop b1 = new Bishop(this, 3, 8, Color.black);
              this.blacks.Add(b1);

              Bishop b2 = new Bishop(this, 6, 8, Color.black);
              this.blacks.Add(b2);

              Bishop wb1 = new Bishop(this, 3, 1, Color.white);
              this.whites.Add(wb1);

              Bishop wb2 = new Bishop(this, 6, 1, Color.white);
              this.whites.Add(wb2);

              Rook r1 = new Rook(this, 1, 8, Color.black);
              this.blacks.Add(r1);

              Rook r2 = new Rook(this, 8, 8, Color.black);
              this.blacks.Add(r2);

              Rook wr1 = new Rook(this, 1, 1, Color.white);
              this.whites.Add(wr1);

              Rook wr2 = new Rook(this, 8, 1, Color.white);
              this.whites.Add(wr2);

              Knight kn1 = new Knight(this, 2, 8, Color.black);
              this.blacks.Add(kn1);

              Knight kn2 = new Knight(this, 7, 8, Color.black);
              this.blacks.Add(kn2);

              Knight wkn1 = new Knight(this, 2, 1, Color.white);
              this.whites.Add(wkn1);

              Knight wkn2 = new Knight(this, 7, 1, Color.white);
              this.whites.Add(wkn2);

              var q = new Queen(this, 4, 8, Color.black);
              this.blacks.Add(q);

              var wq = new Queen(this, 4, 1, Color.white);
              this.whites.Add(wq);

              var k = new King(this, 5, 8, Color.black);
              this.blacks.Add(k);

              var wk = new King(this, 5, 1, Color.white);
              this.whites.Add(wk);

              this.UpdateAllBeatFields();
        }
示例#31
0
文件: Tests.cs 项目: dorotak/TDDKatas
        public void TheKnightIsOnTheBoard()
        {
            var board = new Board(8, 8);
            var initialCoordintates = new Vector(4, 4);

            var knight = new Knight(initialCoordintates, board);
            Assert.That(knight.IsOnTheBoard, Is.EqualTo(true));

            initialCoordintates = new Vector(9, 4);
            var knight2 = new Knight(initialCoordintates, board);
            Assert.That(knight2.IsOnTheBoard, Is.EqualTo(false));
        }
示例#32
0
    void Start()
    {
        knight = GetComponent<Knight>();
        GetIndicatorSprite();
        //basic stats
        healthBar = GameObject.Find("Player" + knight.PlayerID + "Health").GetComponent<Image>();
        healthNumber = GameObject.Find("Player" + knight.PlayerID + "HealthNumber").GetComponent<Text>();
        skillpoints = GameObject.Find("Player" + knight.PlayerID + "SkillPoints").GetComponent<Text>();
        level = GameObject.Find("Player" + knight.PlayerID + "Level").GetComponent<Text>();
        //cooldown count
        ability1TimerNumber = GameObject.Find("Player" + knight.PlayerID + "Ability1TimerNumber").GetComponent<Text>();
        ability2TimerNumber = GameObject.Find("Player" + knight.PlayerID + "Ability2TimerNumber").GetComponent<Text>();
        ability3TimerNumber = GameObject.Find("Player" + knight.PlayerID + "Ability3TimerNumber").GetComponent<Text>();
        ability4TimerNumber = GameObject.Find("Player" + knight.PlayerID + "Ability4TimerNumber").GetComponent<Text>();
        //cooldowns fill
        AbilityTimer1 = GameObject.Find("Player" + knight.PlayerID + "Ability1Timer").GetComponent<Image>();
        AbilityTimer2 = GameObject.Find("Player" + knight.PlayerID + "Ability2Timer").GetComponent<Image>();
        AbilityTimer3 = GameObject.Find("Player" + knight.PlayerID + "Ability3Timer").GetComponent<Image>();
        AbilityTimer4 = GameObject.Find("Player" + knight.PlayerID + "Ability4Timer").GetComponent<Image>();
        experienceBar = GameObject.Find("Player" + knight.PlayerID + "ExperienceBar").GetComponent<Image>();
        //skill backgrounds
        agilityBG = GameObject.Find("Player" + knight.PlayerID + "AGI_BG").GetComponent<Image>();
        powerBG = GameObject.Find("Player" + knight.PlayerID + "PWR_BG").GetComponent<Image>();
        defenseBG = GameObject.Find("Player" + knight.PlayerID + "DEF_BG").GetComponent<Image>();
        //skillpoints counter
        agilityAmount = GameObject.Find("Player" + knight.PlayerID + "AGI").GetComponent<Text>();
        powerAmount = GameObject.Find("Player" + knight.PlayerID + "POW").GetComponent<Text>();
        defAmount = GameObject.Find("Player" + knight.PlayerID + "DEF").GetComponent<Text>();

        //default not on
        agilityAmount.enabled = false;
        powerAmount.enabled = false;
        defAmount.enabled = false;
    }
示例#33
0
文件: Board.cs 项目: jaraki/Chess
    private void AddStartingPieces()
    {
        // add pawns
        for (int i = 0; i < RankCount; ++i)
        {
            Pawn p = CreatePiece(1, i, Color.white, "White Pawn ", typeof(Pawn)) as Pawn;
            p.color           = Color.white;
            p.square          = board[1, i];
            board[1, i].piece = p;
            whitePieces.Add(p);
            p                 = CreatePiece(6, i, Color.black, "Black Pawn ", typeof(Pawn)) as Pawn;
            p.color           = Color.black;
            p.square          = board[6, i];
            board[6, i].piece = p;
            blackPieces.Add(p);
        }
        // add rooks
        Rook r = CreatePiece(0, 0, Color.white, "White Rook ", typeof(Rook)) as Rook;

        r.color           = Color.white;
        r.square          = board[0, 0];
        board[0, 0].piece = r;
        whitePieces.Add(r);
        r                 = CreatePiece(0, 7, Color.white, "White Rook ", typeof(Rook)) as Rook;
        r.color           = Color.white;
        r.square          = board[0, 7];
        board[0, 7].piece = r;
        whitePieces.Add(r);
        r                 = CreatePiece(7, 0, Color.black, "Black Rook ", typeof(Rook)) as Rook;
        r.color           = Color.black;
        r.square          = board[7, 0];
        board[7, 0].piece = r;
        blackPieces.Add(r);
        r                 = CreatePiece(7, 7, Color.black, "Black Rook ", typeof(Rook)) as Rook;
        r.color           = Color.black;
        r.square          = board[7, 7];
        board[7, 7].piece = r;
        blackPieces.Add(r);
        // add knights
        Knight n = CreatePiece(0, 1, Color.white, "White Knight ", typeof(Knight)) as Knight;

        n.color           = Color.white;
        n.square          = board[0, 1];
        board[0, 1].piece = n;
        whitePieces.Add(n);
        n                 = CreatePiece(0, 6, Color.white, "White Knight ", typeof(Knight)) as Knight;
        n.color           = Color.white;
        n.square          = board[0, 6];
        board[0, 6].piece = n;
        whitePieces.Add(n);
        n                 = CreatePiece(7, 1, Color.black, "Black Knight ", typeof(Knight)) as Knight;
        n.color           = Color.black;
        n.square          = board[7, 1];
        board[7, 1].piece = n;
        blackPieces.Add(n);
        n                 = CreatePiece(7, 6, Color.black, "Black Knight ", typeof(Knight)) as Knight;
        n.color           = Color.black;
        n.square          = board[7, 6];
        board[7, 6].piece = n;
        blackPieces.Add(n);
        // add bishops
        Bishop b = CreatePiece(0, 2, Color.white, "White Bishop ", typeof(Bishop)) as Bishop;

        b.color           = Color.white;
        b.square          = board[0, 2];
        board[0, 2].piece = b;
        whitePieces.Add(b);
        b                 = CreatePiece(0, 5, Color.white, "White Bishop ", typeof(Bishop)) as Bishop;
        b.color           = Color.white;
        b.square          = board[0, 5];
        board[0, 5].piece = b;
        whitePieces.Add(b);
        b                 = CreatePiece(7, 2, Color.black, "Black Bishop ", typeof(Bishop)) as Bishop;
        b.color           = Color.black;
        b.square          = board[7, 2];
        board[7, 2].piece = b;
        blackPieces.Add(b);
        b                 = CreatePiece(7, 5, Color.black, "Black Bishop ", typeof(Bishop)) as Bishop;
        b.color           = Color.black;
        b.square          = board[7, 5];
        board[7, 5].piece = b;
        blackPieces.Add(b);
        // add kings
        King k = CreatePiece(0, 4, Color.white, "White King ", typeof(King)) as King;

        k.color           = Color.white;
        k.square          = board[0, 4];
        board[0, 4].piece = k;
        k                 = CreatePiece(7, 4, Color.black, "Black King ", typeof(King)) as King;
        k.color           = Color.black;
        k.square          = board[7, 4];
        board[7, 4].piece = k;
        // add queens
        Queen q = CreatePiece(0, 3, Color.white, "White Queen ", typeof(Queen)) as Queen;

        q.color           = Color.white;
        q.square          = board[0, 3];
        board[0, 3].piece = q;
        whitePieces.Add(q);
        q                 = CreatePiece(7, 3, Color.black, "Black Queen ", typeof(Queen)) as Queen;
        q.color           = Color.black;
        q.square          = board[7, 3];
        board[7, 3].piece = q;
        blackPieces.Add(q);
    }
示例#34
0
 /// <summary>
 /// Called when attacking a knight
 /// </summary>
 /// <param name="knight"></param>
 protected void Attack(Knight knight)
 {
     knight.BeingHit();
     this.BeingHit();
 }
示例#35
0
 public void SetUp()
 {
     arthur = new Knight("Arthur");
 }
            // images[blksq/whtsq][side][idx] - idx = {KING, QUEEN, ROOK, KNIGHT, BISHOP}
            public ChessPiece createPiece(PieceType type,
						       ColorType color,
						       int rank, int file)
            {
                ChessPiece piece = null;
                ChessSide myside, oppside;
                if (color == ColorType.WHITE)
                  {
                      myside = whites;
                      oppside = blacks;
                  }
                else
                  {
                      myside = blacks;
                      oppside = blacks;
                  }

                switch (type)
                  {
                  case PieceType.KING:
                      piece = new King (color, rank, file,
                                myside, oppside);
                      break;
                  case PieceType.QUEEN:
                      piece = new Queen (color, rank,
                                 file, myside,
                                 oppside);
                      break;
                  case PieceType.ROOK:
                      piece = new Rook (color, rank, file,
                                myside, oppside);
                      break;
                  case PieceType.KNIGHT:
                      piece = new Knight (color, rank,
                                  file, myside,
                                  oppside);
                      break;
                  case PieceType.BISHOP:
                      piece = new Bishop (color, rank,
                                  file, myside,
                                  oppside);
                      break;
                  default:
                      return null;
                  }

                return piece;
            }
示例#37
0
 public void TestKnightWeapon()
 {
     HeadFirstDesignPatterns.Strategy.Character.Knight KnightWeapon = new Knight();
     Assert.AreEqual("I shot my arrow at thee!", KnightWeapon.Fight());
 }
示例#38
0
 internal Knight Create(Knight knightData)
 {
     _repo.Create(knightData);
     return(knightData);
 }
示例#39
0
        public int AttackedBySquare(bool sideToMove, int[] board, int squareInQuestion)
        {
            var imaginaryKnight        = new Knight(board, squareInQuestion, sideToMove);
            var listOfAttackingSquares = imaginaryKnight.MoveGeneration();

            foreach (var square in listOfAttackingSquares)
            {
                if (board[square] == Definitions.WhiteKnight || board[square] == Definitions.BlackKnight)
                {
                    return(square);
                }
            }

            var imaginaryBishop   = new Bishop(board, squareInQuestion, sideToMove);
            var listOfBishopMoves = imaginaryBishop.MoveGeneration();

            foreach (var possibleAttackedFromSquare in listOfBishopMoves)
            {
                if (board[possibleAttackedFromSquare] == Definitions.WhiteQueen ||
                    board[possibleAttackedFromSquare] == Definitions.BlackQueen ||
                    board[possibleAttackedFromSquare] == Definitions.WhiteBishop ||
                    board[possibleAttackedFromSquare] == Definitions.BlackBishop)
                {
                    return(possibleAttackedFromSquare);
                }
            }

            var imaginaryKing   = new King(board, squareInQuestion, sideToMove);
            var listOfKingMoves = imaginaryKing.MoveGeneration();

            foreach (var possibleAttackedFromSquare in listOfKingMoves)
            {
                if (board[possibleAttackedFromSquare] == Definitions.WhiteKing ||
                    board[possibleAttackedFromSquare] == Definitions.BlackKing)
                {
                    return(possibleAttackedFromSquare);
                }
            }

            if (sideToMove == Definitions.WhiteToMove)
            {
                // Check if black has pawns that can attack us.
                if (board[squareInQuestion + 11] == Definitions.BlackPawn)
                {
                    return(squareInQuestion + 11);
                }

                if (board[squareInQuestion + 9] == Definitions.BlackPawn)
                {
                    return(squareInQuestion + 9);
                }
            }
            else
            {
                // Check if white has pawns that can attack us.
                if (board[squareInQuestion - 11] == Definitions.WhitePawn)
                {
                    return(squareInQuestion - 11);
                }

                if (board[squareInQuestion - 9] == Definitions.WhitePawn)
                {
                    return(squareInQuestion - 9);
                }
            }

            var imaginaryRook   = new Rook(board, squareInQuestion, sideToMove);
            var listOfRookMoves = imaginaryRook.MoveGeneration();

            foreach (var possibleAttackedFromSquares in listOfRookMoves)
            {
                if (board[possibleAttackedFromSquares] == Definitions.WhiteQueen ||
                    board[possibleAttackedFromSquares] == Definitions.BlackQueen ||
                    board[possibleAttackedFromSquares] == Definitions.WhiteRook ||
                    board[possibleAttackedFromSquares] == Definitions.BlackRook)
                {
                    return(possibleAttackedFromSquares);
                }
            }

            return(99);
        }
示例#40
0
        private static IPiece InitialPieceAtLocation(Rank rank, File file)
        {
            var emptyRanks = new[] { Rank.Three, Rank.Four, Rank.Five, Rank.Six};
            if (emptyRanks.Contains(rank))
            {
                return null;
            }

            var colour = PlayerColour.Black;
            if (rank == Rank.One || rank == Rank.Two)
            {
                colour = PlayerColour.White;
            }

            IPiece piece = new Rook(colour);
            if (rank == Rank.Seven || rank == Rank.Two)
            {
                piece = new Pawn(colour);
            }
            else if (file == File.B || file == File.G)
            {
                piece = new Knight(colour);
            }
            else if (file == File.C || file == File.F)
            {
                piece = new Bishop(colour);
            }
            else if (file == File.D)
            {
                piece = new Queen(colour);
            }
            else if (file == File.E)
            {
                piece = new King(colour);
            }

            return piece;
        }
示例#41
0
        private List <Piece> AddPieces(bool isWhite)
        {
            List <Piece> pieces = new List <Piece>();

            int colStart = isWhite ? 0 : 6;
            int colEnd   = isWhite ? 2 : 8;

            for (int i = 0; i < 8; i++)
            {
                for (int j = colStart; j < colEnd; j++)
                {
                    if ((isWhite && j == colStart) || (!isWhite && j != colStart))
                    {
                        switch (i)
                        {
                        case 0:
                        case 7:
                        {
                            matrix[i, j] = new Rook(isWhite, i, j, matrix);
                        }
                        break;

                        case 1:
                        case 6:
                        {
                            matrix[i, j] = new Knight(isWhite, i, j, matrix);
                        }
                        break;

                        case 2:
                        case 5:
                        {
                            matrix[i, j] = new Bishop(isWhite, i, j, matrix);
                        }
                        break;

                        case 3:
                        {
                            matrix[i, j] = new Queen(isWhite, i, j, matrix);
                        }
                        break;

                        case 4:
                        {
                            matrix[i, j] = new King(isWhite, i, j, matrix);

                            if (isWhite)
                            {
                                whiteKing = matrix[i, j].Start;
                            }
                            else
                            {
                                blackKing = matrix[i, j].Start;
                            }
                        }
                        break;
                        }
                        pieces.Add(matrix[i, j]);
                    }
                    else
                    {
                        matrix[i, j] = new Pawn(isWhite, i, j, matrix);
                        pieces.Add(matrix[i, j]);
                    }
                }
            }

            return(pieces);
        }
示例#42
0
        public bool CanMove(string move)
        {
            //pt ce piesa se aplica mutarea
            var startX = Int32.Parse(move[1].ToString()) - 1;
            //Console.WriteLine("startx board: " + startX);
            var startY = move[0] - 'a';
            //Console.WriteLine("starty board: " + startY);

            var endY = move[3] - 'a';
            //Console.WriteLine("Endy board: " + endY);
            var endX = Int32.Parse(move[4].ToString()) - 1;

            //Console.WriteLine("Endx board: " + endX);

            if (TablaSah[startX, startY] == null)
            {
                //Console.WriteLine("Nu exista piesa pe aceasta pozitie");
                return(false);
            }
            else
            {
                if (TablaSah[startX, startY].Name == "K")
                {
                    Piece king = new King();
                    return(king.Move(TablaSah, move));
                }

                if (TablaSah[startX, startY].Name == "Q")
                {
                    Piece queen = new Queen();
                    if (queen.Move(TablaSah, move) == true && queen.CheckIfMove(TablaSah, move) == false)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (TablaSah[startX, startY].Name == "B")
                {
                    Piece bishop = new Bishop();
                    if (bishop.Move(TablaSah, move) == true && bishop.CheckIfMove(TablaSah, move) == false)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (TablaSah[startX, startY].Name == "N")
                {
                    Piece knight = new Knight();
                    if (knight.Move(TablaSah, move) == true && knight.CheckIfMove(TablaSah, move) == false)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (TablaSah[startX, startY].Name == "P")
                {
                    Piece pawn = new Pawn();
                    if (pawn.Move(TablaSah, move) == true && pawn.CheckIfMove(TablaSah, move) == false)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (TablaSah[startX, startY].Name == "R")
                {
                    Piece rook = new Rook();
                    if (rook.Move(TablaSah, move) == true && rook.CheckIfMove(TablaSah, move) == false)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            return(false);
        }
示例#43
0
        public void Initialize()
        {
            Pieces      = new List <Piece>();
            Renderables = new List <IRenderable>();

            var king = new King()
            {
                X = 4, Y = 0
            };

            Pieces.Add(king);

            var queen = new Queen()
            {
                X = 3, Y = 0
            };

            Pieces.Add(queen);

            var bishop1 = new Bishop()
            {
                X = 2, Y = 0
            };

            Pieces.Add(bishop1);

            var bishop2 = new Bishop()
            {
                X = 5, Y = 0
            };

            Pieces.Add(bishop2);

            var knight1 = new Knight()
            {
                X = 1, Y = 0
            };

            Pieces.Add(knight1);

            var knight2 = new Knight()
            {
                X = 6, Y = 0
            };

            Pieces.Add(knight2);

            var castle1 = new Castle {
                X = 0, Y = 0
            };

            Pieces.Add(castle1);

            var castle2 = new Castle {
                X = 7, Y = 0
            };

            Pieces.Add(castle2);

            var pawn1 = new Pawn()
            {
                X = 7, Y = 1
            };

            Pieces.Add(pawn1);

            var pawn2 = new Pawn()
            {
                X = 6, Y = 1
            };

            Pieces.Add(pawn2);

            var pawn3 = new Pawn()
            {
                X = 5, Y = 1
            };

            Pieces.Add(pawn3);

            var pawn4 = new Pawn()
            {
                X = 4, Y = 1
            };

            Pieces.Add(pawn4);

            var pawn5 = new Pawn()
            {
                X = 3, Y = 1
            };

            Pieces.Add(pawn5);

            var pawn6 = new Pawn()
            {
                X = 2, Y = 1
            };

            Pieces.Add(pawn6);

            var pawn7 = new Pawn()
            {
                X = 1, Y = 1
            };

            Pieces.Add(pawn7);

            var pawn8 = new Pawn()
            {
                X = 0, Y = 1
            };

            Pieces.Add(pawn8);

            foreach (var piece in Pieces)
            {
                Renderables.Add(piece);
                piece.Visible = true;
                piece.GetMoves();
            }
        }
示例#44
0
    //create and position the pieces
    void positionTeam(TeamManager team)
    {
        int KingLine = -1;
        int PawnLine = -1;

        if (team.teamEnum == ChessColor.White)
        {
            KingLine = 0;
            PawnLine = 1;
        }
        else
        {
            KingLine = 7;
            PawnLine = 6;
        }

        int KingColumn = 4;

        team.king = new King();
        board.SetPieceOnBox(team.king, KingLine, KingColumn, team);
        team.king.name = "King_" + team.teamEnum;

        Queen queen = new Queen();

        board.SetPieceOnBox(queen, KingLine, KingColumn - 1, team);
        team.queens[0].name = "Queen_" + team.teamEnum;

        Bishop fool = new Bishop();

        board.SetPieceOnBox(fool, KingLine, KingColumn - 2, team);
        team.bishops[0].name = "Bishop1_" + team.teamEnum;

        Bishop fool2 = new Bishop();

        board.SetPieceOnBox(fool2, KingLine, KingColumn + 1, team);
        team.bishops[1].name = "Bishop2_" + team.teamEnum;

        Knight knight = new Knight();

        board.SetPieceOnBox(knight, KingLine, KingColumn - 3, team);
        team.knights[0].name = "Knight1_" + team.teamEnum;

        Knight knight2 = new Knight();

        board.SetPieceOnBox(knight2, KingLine, KingColumn + 2, team);
        team.knights[1].name = "Knight2_" + team.teamEnum;

        Rook rook = new Rook();

        board.SetPieceOnBox(rook, KingLine, KingColumn - 4, team);
        team.rooks[0].name = "Rook1_" + team.teamEnum;

        Rook rook2 = new Rook();

        board.SetPieceOnBox(rook2, KingLine, KingColumn + 3, team);
        team.rooks[1].name = "Rook2_" + team.teamEnum;

        Pawn pawn = null;

        for (int i = 0; i < 8; i++)
        {
            pawn = new Pawn();
            board.SetPieceOnBox(pawn, PawnLine, i, team);
            team.pawns[i].name = "Pawn" + i + "_" + team.teamEnum;
        }
    }
示例#45
0
        public static bool ChessValidator(FigurePositions currentPositions)
        {
            bool hasCheck = false;

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    Names currentFigureName = currentPositions.Position[i, j].Name;

                    if (currentFigureName == Names.None)
                    {
                        continue;
                    }

                    Colors currentFigureColors = currentPositions.Position[i, j].Color;
                    Player currentPlayer;

                    if (currentFigureColors == Colors.White)
                    {
                        currentPlayer = StartProgram.WhitePlayer;
                    }
                    else
                    {
                        currentPlayer = StartProgram.BlackPlayer;
                    }

                    if (currentFigureName == Names.Pawn)
                    {
                        Pawn pawn = new Pawn(currentFigureColors, currentFigureName);
                        hasCheck = pawn.MakesChess(i, j, currentPlayer, currentPositions);
                    }
                    else if (currentFigureName == Names.Bishop)
                    {
                        Bishop bishop = new Bishop(currentFigureColors, currentFigureName);
                        hasCheck = bishop.MakesChess(i, j, currentPlayer, currentPositions);
                    }
                    else if (currentFigureName == Names.Rook)
                    {
                        Rook rook = new Rook(currentFigureColors, currentFigureName);
                        hasCheck = rook.MakesChess(i, j, currentPlayer, currentPositions);
                    }
                    else if (currentFigureName == Names.Queen)
                    {
                        Queen queen = new Queen(currentFigureColors, currentFigureName);
                        hasCheck = queen.MakesChess(i, j, currentPlayer, currentPositions);
                    }
                    else if (currentFigureName == Names.King)
                    {
                        King king = new King(currentFigureColors, currentFigureName);
                        hasCheck = king.MakesChess(i, j, currentPlayer, currentPositions);
                    }
                    else if (currentFigureName == Names.Knight)
                    {
                        Knight knight = new Knight(currentFigureColors, currentFigureName);
                        hasCheck = knight.MakesChess(i, j, currentPlayer, currentPositions);
                    }

                    if (hasCheck)
                    {
                        return(hasCheck);
                    }
                }
            }

            return(hasCheck);
        }
示例#46
0
        private void populateGridWithFigures()
        {
            IFigure leftWhiteRook = new Rook(new Position(7, 0), true);

            grid[7][0].Figure = leftWhiteRook;

            IFigure rightWhiteRook = new Rook(new Position(7, 7), true);

            grid[7][7].Figure = rightWhiteRook;

            IFigure leftWhiteKnight = new Knight(new Position(7, 1), true);

            grid[7][1].Figure = leftWhiteKnight;

            IFigure rightWhiteKnight = new Knight(new Position(7, 6), true);

            grid[7][6].Figure = rightWhiteKnight;

            IFigure leftWhiteBishop = new Bishop(new Position(7, 2), true);

            grid[7][2].Figure = leftWhiteBishop;

            IFigure rightWhiteBishop = new Bishop(new Position(7, 5), true);

            grid[7][5].Figure = rightWhiteBishop;

            IFigure WhiteQueen = new Queen(new Position(7, 3), true);

            grid[7][3].Figure = WhiteQueen;

            IFigure WhiteKing = new King(new Position(7, 4), true);

            grid[7][4].Figure = WhiteKing;


            IFigure leftBlackRook = new Rook(new Position(0, 0), false);

            grid[0][0].Figure = leftBlackRook;

            IFigure rightBlackRook = new Rook(new Position(0, 7), false);

            grid[0][7].Figure = rightBlackRook;

            IFigure leftBlackKnight = new Knight(new Position(0, 1), false);

            grid[0][1].Figure = leftBlackKnight;

            IFigure rightBlackKnight = new Knight(new Position(0, 6), false);

            grid[0][6].Figure = leftBlackKnight;

            IFigure leftBlackBishop = new Bishop(new Position(0, 2), false);

            grid[0][2].Figure = leftBlackBishop;

            IFigure rightBlackBishop = new Bishop(new Position(0, 5), false);

            grid[0][5].Figure = rightBlackBishop;

            IFigure blackQueen = new Queen(new Position(0, 3), false);

            grid[0][3].Figure = blackQueen;

            IFigure blackKing = new King(new Position(0, 4), false);

            grid[0][4].Figure = blackKing;

            IFigure pawn;

            //Black pawns
            for (int i = 0; i < 8; i++)
            {
                pawn = new Pawn(new Position(1, i), false);
                grid[1][i].Figure = pawn;
            }

            //White pawns
            for (int i = 0; i < 8; i++)
            {
                pawn = new Pawn(new Position(6, i), true);
                grid[6][i].Figure = pawn;
            }
        }
示例#47
0
        private ChessFigure GetFigure(int row, int col)
        {
            ChessFigure figure = new Empty(row, col);

            // Black Figures
            if (row == 0)
            {
                if (col == 1 || col == 6)
                {
                    figure = new Knight(row, col, "black", @"E:\Repos\Chess\Chess\Images\BlackKnight.png");
                }

                if (col == 3)
                {
                    figure = new Queen(row, col, "black", @"E:\Repos\Chess\Chess\Images\BlackQueen.png");
                }

                if (col == 2 || col == 5)
                {
                    figure = new Bishop(row, col, "black", @"E:\Repos\Chess\Chess\Images\BlackBishop.png");
                }

                if (col == 4)
                {
                    figure = new King(row, col, "black", @"E:\Repos\Chess\Chess\Images\BlackKing.png");
                }

                if (col == 0 || col == 7)
                {
                    figure = new Rook(row, col, "black", @"E:\Repos\Chess\Chess\Images\BlackRook.png");
                }
            }

            // White Figures
            if (row == 7)
            {
                if (col == 1 || col == 6)
                {
                    figure = new Knight(row, col, "white", @"E:\Repos\Chess\Chess\Images\WhiteKnight.png");
                }

                if (col == 3)
                {
                    figure = new Queen(row, col, "white", @"E:\Repos\Chess\Chess\Images\WhiteQueen.png");
                }

                if (col == 2 || col == 5)
                {
                    figure = new Bishop(row, col, "white", @"E:\Repos\Chess\Chess\Images\WhiteBishop.png");
                }

                if (col == 4)
                {
                    figure = new King(row, col, "white", @"E:\Repos\Chess\Chess\Images\WhiteKing.png");
                }

                if (col == 0 || col == 7)
                {
                    figure = new Rook(row, col, "white", @"E:\Repos\Chess\Chess\Images\WhiteRook.png");
                }
            }

            if (row == 1)
            {
                figure = new Pawn(row, col, "black", @"E:\Repos\Chess\Chess\Images\BlackPawn.png");
            }

            if (row == 6)
            {
                figure = new Pawn(row, col, "white", @"E:\Repos\Chess\Chess\Images\WhitePawn.png");
            }

            return(figure);
        }
示例#48
0
 public bool Transform(sbyte x, sbyte y, FigureTypes type)
 {
     Figure p = this.GetFigureByXY(x, y);
       if (p.type != FigureTypes.Pawn)
     return false;
       Figure newFigure;
       switch (type)
       {
     case FigureTypes.Knight:
       newFigure = new Knight(this, p.field.x, p.field.y, p.color);
       break;
     case FigureTypes.Bishop:
       newFigure = new Bishop(this, p.field.x, p.field.y, p.color);
       break;
     case FigureTypes.Queen:
       newFigure = new Queen(this, p.field.x, p.field.y, p.color);
       break;
     case FigureTypes.Rook:
       newFigure = new Rook(this, p.field.x, p.field.y, p.color);
       break;
     default:
       return false;
       }
       if (p.color == Color.white)
       {
     this.whites.Remove(p);
     this.whites.Add(newFigure);
       }
       else
       {
     this.blacks.Remove(p);
     this.blacks.Add(newFigure);
       }
       this.UpdateAllBeatFields();
       this.IsGameOvered();
       return true;
 }
示例#49
0
        public ChessTile(bool botVSbot, bool isWhite, double pawnWeightOpp1, double rookWeightOpp1,
                         double bishopWeightOpp1, double knightWeightOpp1, double queenWeightOpp1,
                         double kingWeightOpp1, double pawnWeightOpp2, double rookWeightOpp2,
                         double bishopWeightOpp2, double knightWeightOpp2, double queenWeightOpp2, double kingWeightOpp2)
        {
            this.IsWhite = isWhite;
            if (IsWhite)
            {
                oneHand = "white";
            }
            else
            {
                otherHand = "white";
            }

            Figures = new List <Figure>();
            for (int i = 0; i < 8; i++)
            {
                Pawn p = new Pawn();
                p.IsWhite = IsWhite;
                p.ImgPath = "addons/pawn_" + oneHand + ".png";
                p.Coord   = new int[2] {
                    i, 6
                };
                p.Weight = pawnWeightOpp1;
                Figures.Add(p);
            }

            for (int i = 0; i < 8; i++)
            {
                Pawn p = new Pawn();
                p.IsWhite = !IsWhite;
                p.ImgPath = "addons/pawn_" + otherHand + ".png";
                p.Coord   = new int[2] {
                    i, 1
                };
                p.Weight = pawnWeightOpp2;
                Figures.Add(p);
            }

            for (int i = 0; i < 8; i += 7)
            {
                Rook r = new Rook();
                r.IsWhite = IsWhite;
                r.ImgPath = "addons/rook_" + oneHand + ".png";
                r.Coord   = new int[2] {
                    i, 7
                };
                r.Weight = rookWeightOpp1;
                Figures.Add(r);
            }

            for (int i = 0; i < 8; i += 7)
            {
                Rook r = new Rook();
                r.IsWhite = !IsWhite;
                r.ImgPath = "addons/rook_" + otherHand + ".png";
                r.Coord   = new int[2] {
                    i, 0
                };
                r.Weight = rookWeightOpp2;
                Figures.Add(r);
            }

            for (int i = 2; i < 8; i += 3)
            {
                Bishop b = new Bishop();
                b.IsWhite = IsWhite;
                b.ImgPath = "addons/bishop_" + oneHand + ".png";
                b.Coord   = new int[2] {
                    i, 7
                };
                b.Weight = bishopWeightOpp1;
                Figures.Add(b);
            }

            for (int i = 2; i < 8; i += 3)
            {
                Bishop b = new Bishop();
                b.IsWhite = !IsWhite;
                b.ImgPath = "addons/bishop_" + otherHand + ".png";
                b.Coord   = new int[2] {
                    i, 0
                };
                b.Weight = bishopWeightOpp2;
                Figures.Add(b);
            }

            for (int i = 1; i < 8; i += 5)
            {
                Knight kn = new Knight();
                kn.IsWhite = IsWhite;
                kn.ImgPath = "addons/knight_" + oneHand + ".png";
                kn.Coord   = new int[2] {
                    i, 7
                };
                kn.Weight = knightWeightOpp1;
                Figures.Add(kn);
            }

            for (int i = 1; i < 8; i += 5)
            {
                Knight kn = new Knight();
                kn.IsWhite = !IsWhite;
                kn.ImgPath = "addons/knight_" + otherHand + ".png";
                kn.Coord   = new int[2] {
                    i, 0
                };
                kn.Weight = knightWeightOpp2;
                Figures.Add(kn);
            }

            Queen q = new Queen();

            q.IsWhite = IsWhite;
            q.ImgPath = "addons/queen_" + oneHand + ".png";
            q.Coord   = new int[2] {
                3, 7
            };
            q.Weight = queenWeightOpp1;
            Figures.Add(q);

            q         = new Queen();
            q.IsWhite = !IsWhite;
            q.ImgPath = "addons/queen_" + otherHand + ".png";
            q.Coord   = new int[2] {
                3, 0
            };
            q.Weight = queenWeightOpp2;
            Figures.Add(q);

            King k = new King();

            k.IsWhite = IsWhite;
            k.ImgPath = "addons/king_" + oneHand + ".png";
            k.Coord   = new int[2] {
                4, 7
            };
            k.Weight = kingWeightOpp1;
            Figures.Add(k);

            k         = new King();
            k.IsWhite = !IsWhite;
            k.ImgPath = "addons/king_" + otherHand + ".png";
            k.Coord   = new int[2] {
                4, 0
            };
            k.Weight = kingWeightOpp2;
            Figures.Add(k);
        }
示例#50
0
        public void TestAttackAndTake()
        {
            GameObject GameObject = new GameObject();
              GameObject.whites = new List<Figure>();
              GameObject.blacks = new List<Figure>();
              King wKing = new King(GameObject, 1, 1, Color.white);
              King bKing = new King(GameObject, 8, 8, Color.black);
              Knight bKnight = new Knight(GameObject, 5, 5, Color.black);
              Knight wKnight = new Knight(GameObject, 5, 4, Color.white);
              GameObject.whites.Add(wKing);
              GameObject.blacks.Add(bKing);
              GameObject.blacks.Add(bKnight);
              GameObject.whites.Add(wKnight);

              // knights in the middle of the field
              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(wKnight.CanAttackPosition(3, 5));
              Assert.IsTrue(wKnight.CanAttackPosition(3, 3));
              Assert.IsTrue(wKnight.CanAttackPosition(4, 6));
              Assert.IsTrue(wKnight.CanAttackPosition(4, 2));
              Assert.IsTrue(wKnight.CanAttackPosition(6, 6));
              Assert.IsTrue(wKnight.CanAttackPosition(6, 2));
              Assert.IsTrue(wKnight.CanAttackPosition(7, 3));
              Assert.IsTrue(wKnight.CanAttackPosition(7, 5));

              Assert.IsTrue(bKnight.CanAttackPosition(3, 6));
              Assert.IsTrue(bKnight.CanAttackPosition(3, 4));
              Assert.IsTrue(bKnight.CanAttackPosition(4, 7));
              Assert.IsTrue(bKnight.CanAttackPosition(4, 3));
              Assert.IsTrue(bKnight.CanAttackPosition(6, 7));
              Assert.IsTrue(bKnight.CanAttackPosition(6, 3));
              Assert.IsTrue(bKnight.CanAttackPosition(7, 4));
              Assert.IsTrue(bKnight.CanAttackPosition(7, 6));

              // knights at the border of the field
              bKnight.field.x = 8;
              bKnight.field.y = 7;
              wKnight.field.x = 3;
              wKnight.field.y = 2;
              GameObject.UpdateAllBeatFields();

              Assert.IsTrue(wKnight.CanAttackPosition(1, 3));
              Assert.IsTrue(wKnight.CanAttackPosition(2, 4));
              Assert.IsTrue(wKnight.CanAttackPosition(4, 4));
              Assert.IsTrue(wKnight.CanAttackPosition(5, 3));
              Assert.IsTrue(wKnight.CanAttackPosition(5, 1));

              Assert.IsTrue(bKnight.CanMoveToPosition(6, 8));
              Assert.IsTrue(bKnight.CanMoveToPosition(6, 6));
              Assert.IsTrue(bKnight.CanMoveToPosition(7, 5));

              // Add black pawns
              Pawn bp1 = new Pawn(GameObject, 2, 4, Color.black);
              Pawn bp2 = new Pawn(GameObject, 5, 3, Color.black);
              GameObject.blacks.Add(bp1);
              GameObject.blacks.Add(bp2);
              Assert.IsTrue(wKnight.CanAttackPosition(1, 3));
              Assert.IsTrue(wKnight.CanAttackPosition(2, 4));
              Assert.IsTrue(wKnight.CanAttackPosition(4, 4));
              Assert.IsTrue(wKnight.CanAttackPosition(5, 3));
              Assert.IsTrue(wKnight.CanAttackPosition(5, 1));
        }
            private static void GetPieceForFENChar(char fench,
								ChessSide
								whites,
								ChessSide
								blacks,
								int rank,
								int file,
								out ChessPiece
								piece)
            {
                ColorType color;
                ChessSide myside, oppside;
                if (Char.IsUpper (fench))
                  {
                      color = ColorType.WHITE;
                      myside = whites;
                      oppside = blacks;
                  }
                else
                  {
                      color = ColorType.BLACK;
                      myside = blacks;
                      oppside = whites;
                  }

                char ch = Char.ToLower (fench);
                switch (ch)
                  {
                  case 'p':
                      piece = new Pawn (color, rank, file,
                                myside, oppside);
                      break;
                  case 'k':
                      piece = new King (color, rank, file,
                                myside, oppside);
                      break;
                  case 'q':
                      piece = new Queen (color, rank,
                                 file, myside,
                                 oppside);
                      break;
                  case 'b':
                      piece = new Bishop (color, rank,
                                  file, myside,
                                  oppside);
                      break;
                  case 's':
                      piece = new Knight (color, rank,
                                  file, myside,
                                  oppside);
                      break;
                  case 'n':
                      piece = new Knight (color, rank,
                                  file, myside,
                                  oppside);
                      break;
                  case 'r':
                      piece = new Rook (color, rank, file,
                                myside, oppside);
                      break;
                  default:
                      throw new
                          ChessException
                          (Catalog.GetString("Invalid piece type ") +
                           ch);
                  }
            }
示例#52
0
        public void TestMove()
        {
            GameObject GameObject = new GameObject();
              GameObject.whites = new List<Figure>();
              GameObject.blacks = new List<Figure>();
              King wKing = new King(GameObject, 1, 1, Color.white);
              King bKing = new King(GameObject, 8, 8, Color.black);
              Knight bKnight = new Knight(GameObject, 5, 5, Color.black);
              Knight wKnight = new Knight(GameObject, 5, 4, Color.white);
              GameObject.whites.Add(wKing);
              GameObject.blacks.Add(bKing);
              GameObject.blacks.Add(bKnight);
              GameObject.whites.Add(wKnight);

              // knights in the middle of the field
              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(wKnight.MoveFields.Count == 8);
              Assert.IsTrue(wKnight.CanMoveToPosition(3, 5));
              Assert.IsTrue(wKnight.CanMoveToPosition(3, 3));
              Assert.IsTrue(wKnight.CanMoveToPosition(4, 6));
              Assert.IsTrue(wKnight.CanMoveToPosition(4, 2));
              Assert.IsTrue(wKnight.CanMoveToPosition(6, 6));
              Assert.IsTrue(wKnight.CanMoveToPosition(6, 2));
              Assert.IsTrue(wKnight.CanMoveToPosition(7, 3));
              Assert.IsTrue(wKnight.CanMoveToPosition(7, 5));

              Assert.IsTrue(bKnight.MoveFields.Count == 8);
              Assert.IsTrue(bKnight.CanMoveToPosition(3, 6));
              Assert.IsTrue(bKnight.CanMoveToPosition(3, 4));
              Assert.IsTrue(bKnight.CanMoveToPosition(4, 7));
              Assert.IsTrue(bKnight.CanMoveToPosition(4, 3));
              Assert.IsTrue(bKnight.CanMoveToPosition(6, 7));
              Assert.IsTrue(bKnight.CanMoveToPosition(6, 3));
              Assert.IsTrue(bKnight.CanMoveToPosition(7, 4));
              Assert.IsTrue(bKnight.CanMoveToPosition(7, 6));

              // knights at the border of the field
              bKnight.field.x = 8;
              bKnight.field.y = 7;
              wKnight.field.x = 3;
              wKnight.field.y = 2;
              GameObject.UpdateAllBeatFields();

              Assert.IsTrue(wKnight.MoveFields.Count == 5);
              Assert.IsTrue(wKnight.CanMoveToPosition(1, 3));
              Assert.IsTrue(wKnight.CanMoveToPosition(2, 4));
              Assert.IsTrue(wKnight.CanMoveToPosition(4, 4));
              Assert.IsTrue(wKnight.CanMoveToPosition(5, 3));
              Assert.IsTrue(wKnight.CanMoveToPosition(5, 1));

              Assert.IsTrue(bKnight.MoveFields.Count == 3);
              Assert.IsTrue(bKnight.CanMoveToPosition(6, 8));
              Assert.IsTrue(bKnight.CanMoveToPosition(6, 6));
              Assert.IsTrue(bKnight.CanMoveToPosition(7, 5));

              // Add white rook
              Rook wRook = new Rook(GameObject, 8, 2, Color.white);
              GameObject.whites.Add(wRook);
              GameObject.UpdateAllBeatFields();

              Assert.IsTrue(wRook.Move(8, 3));
              Assert.IsFalse(bKnight.Move(6, 8)); // Can't move knight - open attack on king
              Assert.IsTrue(bKnight.field.x == 8 && bKnight.field.y == 7);
              Assert.IsFalse(bKnight.Move(6, 6)); // Can't move knight - open attack on king
              Assert.IsTrue(bKnight.field.x == 8 && bKnight.field.y == 7);
              Assert.IsFalse(bKnight.Move(7, 5)); // Can't move knight - open attack on king
              Assert.IsTrue(bKnight.field.x == 8 && bKnight.field.y == 7);

              // Add white pawn and beat it by knight
              Pawn p1 = new Pawn(GameObject, 6, 6, Color.white);
              GameObject.whites.Add(p1);
              GameObject.UpdateAllBeatFields();
              Assert.IsFalse(bKnight.Move(6, 6));

              // remove rook
              GameObject.whites.Remove(wRook);
              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(bKnight.Move(6, 6));

              // add white rook
              wRook.field.x = 5;
              wRook.field.y = 1;
              GameObject.whites.Add(wRook);
              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(wRook.Move(5, 8));
              Assert.IsTrue(bKnight.Move(5, 8));

              // add white rook again
              wRook.field.x = 1;
              wRook.field.y = 2;
              bKnight.field.x = 6;
              bKnight.field.y = 6;
              GameObject.whites.Add(wRook);
              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(wRook.Move(1, 8));
              Assert.IsFalse(bKnight.Move(5, 4)); //king not covered
              Assert.IsFalse(bKnight.Move(7, 4)); //king not covered
              Assert.IsTrue(bKnight.Move(7, 8)); //cover king
        }
示例#53
0
        public Board(bool player1)
        {
            Turn           = true;
            TurnNumber     = 0;
            FullMoveNumber = 0;

            this.player1 = player1;

            ChessBoard  = new PieceBase[Constants.Size, Constants.Size];
            WhitePieces = new HashSet <PieceBase>();
            BlackPieces = new HashSet <PieceBase>();

            P1RRookCanCastling = true;
            P1LRookCanCastling = true;
            P2RRookCanCastling = true;
            P2LRookCanCastling = true;

            ChessBoard[0, 1] = new Pawn(player1, 0, 1);
            ChessBoard[1, 1] = new Pawn(player1, 1, 1);
            ChessBoard[2, 1] = new Pawn(player1, 2, 1);
            ChessBoard[3, 1] = new Pawn(player1, 3, 1);
            ChessBoard[4, 1] = new Pawn(player1, 4, 1);
            ChessBoard[5, 1] = new Pawn(player1, 5, 1);
            ChessBoard[6, 1] = new Pawn(player1, 6, 1);
            ChessBoard[7, 1] = new Pawn(player1, 7, 1);

            ChessBoard[0, 6] = new Pawn(!player1, 0, 6);
            ChessBoard[1, 6] = new Pawn(!player1, 1, 6);
            ChessBoard[2, 6] = new Pawn(!player1, 2, 6);
            ChessBoard[3, 6] = new Pawn(!player1, 3, 6);
            ChessBoard[4, 6] = new Pawn(!player1, 4, 6);
            ChessBoard[5, 6] = new Pawn(!player1, 5, 6);
            ChessBoard[6, 6] = new Pawn(!player1, 6, 6);
            ChessBoard[7, 6] = new Pawn(!player1, 7, 6);

            ChessBoard[0, 0] = new Rook(player1, 0, 0);
            ChessBoard[7, 0] = new Rook(player1, 7, 0);
            ChessBoard[0, 7] = new Rook(!player1, 0, 7);
            ChessBoard[7, 7] = new Rook(!player1, 7, 7);

            ChessBoard[1, 0] = new Knight(player1, 1, 0);
            ChessBoard[6, 0] = new Knight(player1, 6, 0);
            ChessBoard[1, 7] = new Knight(!player1, 1, 7);
            ChessBoard[6, 7] = new Knight(!player1, 6, 7);

            ChessBoard[2, 0] = new Bishop(player1, 2, 0);
            ChessBoard[5, 0] = new Bishop(player1, 5, 0);
            ChessBoard[2, 7] = new Bishop(!player1, 2, 7);
            ChessBoard[5, 7] = new Bishop(!player1, 5, 7);

            ChessBoard[4, 0] = new King(player1, 4, 0);
            ChessBoard[4, 7] = new King(!player1, 4, 7);

            ChessBoard[3, 0] = new Queen(player1, 3, 0);
            ChessBoard[3, 7] = new Queen(!player1, 3, 7);

            // creates 2 arrays with same color pieces
            for (int i = Constants.ForStart; i < Constants.ColorPieces / 2; i++)
            {
                WhitePieces.Add(ChessBoard[i, 1]);
                BlackPieces.Add(ChessBoard[i, 6]);
            }
            for (int i = Constants.ForStart; i < Constants.ColorPieces / 2; i++)
            {
                WhitePieces.Add(ChessBoard[i, 0]);
                BlackPieces.Add(ChessBoard[i, 7]);
            }


            for (int i = Constants.ForStart; i < Constants.Size; i++)
            {
                for (int j = Constants.EmptyPieceStartLine; j < Constants.EmptyPieceEndLine; j++)
                {
                    ChessBoard[i, j] = null;
                }
            }
        }
示例#54
0
 public void Number_of_available_positions_is_calculated()
 {
     Assert.That(Knight.PossibleMoves().Count, Is.EqualTo(_numberOfPossibleMoves));
 }
示例#55
0
 // Use this for initialization
 void Start()
 {
     player = knight.GetComponent <Knight>();
 }
示例#56
0
 public void SetPlayer(GameObject character)
 {
     knight = character.GetComponent <Knight>();
     player = character.GetComponent <PlayerController>();
 }
示例#57
0
        //有关数据和数组



        //接受并分析传来的信息
        static Piece DescribePC(char zi)
        {
            Piece pc = new Piece();

            switch (zi)
            {
            case 'r':
                pc = new Rook(); pc.side = false;
                break;

            case 'R':
                pc = new Rook(); pc.side = true;
                break;

            case 'n':
                pc = new Knight(); pc.side = false;
                break;

            case 'N':
                pc = new Knight(); pc.side = true;
                break;

            case 'b':
                pc = new Bishop(); pc.side = false;
                break;

            case 'B':
                pc = new Bishop(); pc.side = true;
                break;

            case 'a':
                pc = new Advisor(); pc.side = false;
                break;

            case 'A':
                pc = new Advisor(); pc.side = true;
                break;

            case 'k':
                pc = new General(); pc.side = false;
                break;

            case 'K':
                pc = new General(); pc.side = true;
                break;

            case 'c':
                pc = new Cannon(); pc.side = false;
                break;

            case 'C':
                pc = new Cannon(); pc.side = true;
                break;

            case 'p':
                pc = new Pawn(); pc.side = false;
                break;

            case 'P':
                pc = new Pawn(); pc.side = true;
                break;

            default:
                break;
            }
            return(pc);
        }
示例#58
0
 // Start is called before the first frame update
 public virtual void Awake()
 {
     currentHealth = health;
     knight        = player.GetComponent <Knight>();
     rb            = gameObject.GetComponent <Rigidbody>();
 }
示例#59
0
        //generare tabla
        public Piece[,] StartGame(string WhitePath, string BlackPath)
        {
            TablaSah   = new Piece[8, 8];
            ListaPiese = ListaPopulare.Read(WhitePath, BlackPath);

            foreach (var piesa in ListaPiese)
            {
                if (piesa[0] == 'w')
                {
                    if (piesa[1] == 'K')
                    {
                        var piesaSah = new King();
                        piesaSah.color = ChessColor.White;

                        TablaSah[Int32.Parse(piesa[3].ToString()) - 1, piesa[2] - 'a'] = piesaSah;
                    }

                    if (piesa[1] == 'Q')
                    {
                        var piesaSah = new Queen();
                        piesaSah.color = ChessColor.White;

                        TablaSah[Int32.Parse(piesa[3].ToString()) - 1, piesa[2] - 'a'] = piesaSah;
                    }

                    if (piesa[1] == 'B')
                    {
                        var piesaSah = new Bishop();
                        piesaSah.color = ChessColor.White;

                        TablaSah[Int32.Parse(piesa[3].ToString()) - 1, piesa[2] - 'a'] = piesaSah;
                    }

                    if (piesa[1] == 'N')
                    {
                        var piesaSah = new Knight();
                        piesaSah.color = ChessColor.White;

                        TablaSah[Int32.Parse(piesa[3].ToString()) - 1, piesa[2] - 'a'] = piesaSah;
                    }

                    if (piesa[1] == 'P')
                    {
                        var piesaSah = new Pawn();
                        piesaSah.color = ChessColor.White;

                        TablaSah[Int32.Parse(piesa[3].ToString()) - 1, piesa[2] - 'a'] = piesaSah;
                    }

                    if (piesa[1] == 'R')
                    {
                        var piesaSah = new Rook();
                        piesaSah.color = ChessColor.White;

                        TablaSah[Int32.Parse(piesa[3].ToString()) - 1, piesa[2] - 'a'] = piesaSah;
                    }
                }
                else
                {
                    if (piesa[1] == 'K')
                    {
                        var piesaSah = new King();
                        piesaSah.color = ChessColor.Black;

                        TablaSah[Int32.Parse(piesa[3].ToString()) - 1, piesa[2] - 'a'] = piesaSah;
                    }

                    if (piesa[1] == 'Q')
                    {
                        var piesaSah = new Queen();
                        piesaSah.color = ChessColor.Black;

                        TablaSah[Int32.Parse(piesa[3].ToString()) - 1, piesa[2] - 'a'] = piesaSah;
                    }

                    if (piesa[1] == 'B')
                    {
                        var piesaSah = new Bishop();
                        piesaSah.color = ChessColor.Black;

                        TablaSah[Int32.Parse(piesa[3].ToString()) - 1, piesa[2] - 'a'] = piesaSah;
                    }

                    if (piesa[1] == 'N')
                    {
                        var piesaSah = new Knight();
                        piesaSah.color = ChessColor.Black;

                        TablaSah[Int32.Parse(piesa[3].ToString()) - 1, piesa[2] - 'a'] = piesaSah;
                    }

                    if (piesa[1] == 'P')
                    {
                        var piesaSah = new Pawn();
                        piesaSah.color = ChessColor.Black;

                        TablaSah[Int32.Parse(piesa[3].ToString()) - 1, piesa[2] - 'a'] = piesaSah;
                    }

                    if (piesa[1] == 'R')
                    {
                        var piesaSah = new Rook();
                        piesaSah.color = ChessColor.Black;

                        TablaSah[Int32.Parse(piesa[3].ToString()) - 1, piesa[2] - 'a'] = piesaSah;
                    }
                }
            }

            return(TablaSah);
        }
示例#60
0
    public void MakeMoveEmptyMoves(Move m)
    {
        if (m.castleMove)
        {
            if (m.castle == 1)
            {
                if (m.blackTurn)
                {
                    pieces.Find(p => p.pieceName.Equals("King_Black")).SetPosition(squares[6, 7]);
                    pieces.Find(p => p.pieceName.Equals("Rook_Black") && p.col == 'H').SetPosition(squares[5, 7]);
                    squares[7, 7].occupant = null;
                    squares[4, 7].occupant = null;
                }
                else
                {
                    pieces.Find(p => p.pieceName.Equals("King_White")).SetPosition(squares[6, 0]);
                    pieces.Find(p => p.pieceName.Equals("Rook_White") && p.col == 'H').SetPosition(squares[5, 0]);
                    squares[7, 0].occupant = null;
                    squares[4, 0].occupant = null;
                }
            }
            else
            {
                if (m.blackTurn)
                {
                    pieces.Find(p => p.pieceName.Equals("King_Black")).SetPosition(squares[2, 7]);
                    pieces.Find(p => p.pieceName.Equals("Rook_Black") && p.col == 'A').SetPosition(squares[3, 7]);
                    squares[0, 7].occupant = null;
                    squares[4, 7].occupant = null;
                }
                else
                {
                    pieces.Find(p => p.pieceName.Equals("King_White")).SetPosition(squares[2, 0]);
                    pieces.Find(p => p.pieceName.Equals("Rook_White") && p.col == 'A').SetPosition(squares[3, 0]);
                    squares[0, 0].occupant = null;
                    squares[4, 0].occupant = null;
                }
            }
            blackToPlay = !blackToPlay;
            return;
        }

        if (m.takeMove)
        {
            pieces.Remove(FindPieceOnBoard(m.colTo, m.rowTo));
        }
        else if (m.enPassant)
        {
            //    Debug.Log("En Passant");
            if (blackToPlay)
            {
                pieces.Remove(FindPieceOnBoard(m.colTo, '4'));
            }
            else
            {
                //          Debug.Log("Removing " + FindPieceOnBoard(m.colTo, '5').pieceName);
                pieces.Remove(FindPieceOnBoard(m.colTo, '5'));
            }
        }
        Piece pieceToMove = FindPieceOnBoard(m.colFrom, m.rowFrom);

        pieceToMove.SetPosition(m.colTo, m.rowTo);
        pieceToMove.hasMoved = true;
        GetSquare(m.colFrom - 'A', m.rowFrom - '1').occupant = null;

        if (m.promoteMove)
        {
            int index = pieces.IndexOf(pieceToMove);
            switch (m.promoteTo)
            {
            case 1: pieces[index] = new Queen(pieceToMove, this); break;

            case 2: pieces[index] = new Rook(pieceToMove, this); break;

            case 3: pieces[index] = new Bishop(pieceToMove, this); break;

            case 4: pieces[index] = new Knight(pieceToMove, this); break;
            }
        }

        foreach (Piece p in pieces)
        {
            if (p.GetType().Name == "Pawn" && pieceToMove == p && Mathf.Abs(m.rowTo - m.rowFrom) == 2)
            {
                p.enPassant = true;
                //   Debug.Log(p.pieceName + " enPassant");
            }
            else
            {
                p.enPassant = false;
            }
        }

        blackToPlay = !blackToPlay;
    }