Exemple #1
0
 public BlackPawnMoveFixture()
 {
     _sut    = new PawnMove();
     _piece  = Helper.GetMockedPieceAt(1, 7);
     _pieces = new List <IPiece> {
         _piece
     };
 }
 public WhitePawnMoveFixture()
 {
     _sut    = new PawnMove();
     _piece  = Helper.GetMockedPieceAt(1, 0, PieceColor.White);
     _pieces = new List <IPiece> {
         _piece
     };
 }
        protected void RemoveCapturedPawn(PawnMove pawnMove)
        {
            if (pawnMove.GetCapturedList().Count <= moveStage)
            {
                return;
            }
            var capPawn   = pawnMove.GetCapturedList().ElementAt(moveStage);
            var fieldInfo = new FieldInfo(PawnColor.NONE, capPawn.GetPosition(), FieldAct.INACTIVE);

            gameBoard.BoardInterface.UpdateField(fieldInfo);
        }
        public void TestPawnMoves()
        {
            chess.CreateChessBoard();
            var pawn     = new PawnMove();
            var outcome1 = pawn.Moves("H7");

            Assert.AreEqual("H6", outcome1.Find(value => value.Equals("H6")));
            var outcome2 = pawn.Moves("A7");

            Assert.AreEqual("A6", outcome2.Find(value => value.Equals("A6")));
            var outcome3 = pawn.Moves("B3");

            Assert.AreEqual("B2", outcome3.Find(value => value.Equals("B2")));
            var outcome4 = pawn.Moves("E5");

            Assert.AreEqual("E4", outcome4.Find(value => value.Equals("E4")));
        }
 protected void CompleteMove(PawnMove pawnMove)
 {
     gameBoard.BoardInterface.UpdateField(new FieldInfo(movedPawn, FieldAct.INACTIVE));
     gameBoard.ChangeState(new FinishMoveStrategy(gameBoard, pawnMove).ResolveState());
 }
Exemple #6
0
 public FinishMoveStrategy(GameBoard gameBoard, PawnMove pawnMove)
 {
     this.gameBoard = gameBoard;
     this.pawnMove  = pawnMove;
 }
        /// <summary>
        /// Execute the automatic logic for play
        /// </summary>
        private void ExecuteAutomatic()
        {
            // Set priorities
            Context.PriorityPawns.Clear();

            foreach (var p in Context.Player.Pawns.Where(x => !x.IsAchieved))
            {
                int priority = 1;

                // Positive: !IsLive, Close to Achieve, Kill Opponent, Protect
                // Negative: Escape
                foreach (PawnMove move in Context.PossibleMoves[p.ID].Where(x => !x.IsUsed))
                {
                    if (!p.IsLive && move.Value == 1)
                    {
                        if (priority < 10)
                        {
                            priority = 10;
                        }
                    }
                    if (p.IsLive)
                    {
                        int[] m = new int[] { 2, 3, 4, 6, 10, 11 };
                        foreach (int i in m)
                        {
                            Cell c = p.GetCellAfter(i);
                            if (c == null)
                            {
                                break;
                            }

                            if (c != null && c.IsShield)
                            {
                                if (priority < 20)
                                {
                                    priority = 20;
                                }
                            }
                            else if (c.Owner != null && c.Owner.ID != p.Owner.ID)
                            {
                                if (priority < 30)
                                {
                                    priority = 30;
                                }
                            }
                        }
                    }
                    if (Context.PriorityPawns.ContainsKey(p.ID))
                    {
                        if (priority > Context.PriorityPawns[p.ID])
                        {
                            Context.PriorityPawns[p.ID] = priority;
                        }
                    }
                    else
                    {
                        Context.PriorityPawns.Add(p.ID, priority);
                    }
                }
            }

            foreach (var id in Context.PriorityPawns.Keys.OrderByDescending(x => Context.PriorityPawns[x]))
            {
                var             pawn  = Context.Player.Pawns.First(x => x.ID == id);
                List <PawnMove> moves = Context.PossibleMoves[pawn.ID];
                if (moves.Count() > 0)
                {
                    PawnMove move = moves.First();
                    if (!move.IsUsed)
                    {
                        move.IsUsed = true;
                        pawn.Move(move.Value);
                        //if (!pawn.IsLive)
                        // pawn.IsLive = true;
                    }
                    foreach (var pmoves in Context.PossibleMoves.Values)
                    {
                        pmoves.RemoveAll(x => x.IsUsed);
                    }
                    break;
                }
            }
            GameApp.Instance.Board.Update();
            GameApp.Instance.Update();
        }