Exemple #1
0
        internal static PossibleMoves ParseResponsePossibleMoves(string response)
        {
            PossibleMoves possMoves = JsonHandler.TryDeserialize <PossibleMoves>(response);

            //Console.WriteLine("Response possMoves: " + "\n" + JObject.Parse(response).ToString());
            return(possMoves);
        }
Exemple #2
0
        // Both players use same strategies when choosing a cell to put their stones
        // and execute them in the following order
        // 1. Can I win in this move (make 5 in a row) (offensive move)
        // 2. Can opponent win in the next move (defensive move)
        // 3. Can I align 4 my stones in a row in this move (offensive)
        // 4. Can opponent align 4 of his stones in a row in the next move (defensive)
        // 5. Can I align 3 my stones in a row in this move (offensive)
        // 6. Can I align 2 my stones in a row in this move (offensive)
        // 7. I make a move on a random empty cell (neutral?)


        // If a player wants to make offensive move he checks possible moves with list of his own moves
        // If a player wants to make defensive move he checks possible moves with list of his opponent's moves
        // Check on each condition is performed step by step until a matching move is found
        // since operations are performed with relatively small list of integers
        // and deep nesting of loops and statements is avoided, players make moves very quickly

        public static void MakeMove()
        {
            if (MoveCount % 2 == 0) // Player 1 chooses next move
            {
                if ((CurrentMove = CheckForFiveInARow(Player1Moves)) == NoSuchMove &&
                    (CurrentMove = CheckForFiveInARow(Player2Moves)) == NoSuchMove &&
                    (CurrentMove = CheckForFourInARow(Player1Moves)) == NoSuchMove &&
                    (CurrentMove = CheckForFourInARow(Player2Moves)) == NoSuchMove &&
                    (CurrentMove = CheckForThreeInARow(Player1Moves)) == NoSuchMove &&
                    (CurrentMove = CheckForTwoInARow(Player1Moves)) == NoSuchMove)
                {
                    CurrentMove = GenerateRandomMove();
                }
                Board[CurrentMove / 100, CurrentMove % 100] = 'x';
                Player1Moves.Add(CurrentMove);
            }
            else // Player 2 chooses next move
            {
                if ((CurrentMove = CheckForFiveInARow(Player2Moves)) == NoSuchMove &&
                    (CurrentMove = CheckForFiveInARow(Player1Moves)) == NoSuchMove &&
                    (CurrentMove = CheckForFourInARow(Player2Moves)) == NoSuchMove &&
                    (CurrentMove = CheckForFourInARow(Player1Moves)) == NoSuchMove &&
                    (CurrentMove = CheckForThreeInARow(Player2Moves)) == NoSuchMove &&
                    (CurrentMove = CheckForTwoInARow(Player2Moves)) == NoSuchMove)
                {
                    CurrentMove = GenerateRandomMove();
                }
                Board[CurrentMove / 100, CurrentMove % 100] = 'o';
                Player2Moves.Add(CurrentMove);
            }

            PossibleMoves.Remove(CurrentMove);
        }
Exemple #3
0
        //Method to Gather moves
        List <int[]> gatherMoves()
        {
            int[] currPos = { PosX, PosY };
            int   a       = 0;
            int   b       = 0;

            //2 spaces in one dimension and 1 space in another are allowed - never 2 in both or 1 in both
            while (b < 3)
            {
                //trip integer
                int trip = 0;

                if (a == 0)
                {
                    //a=1 b=2 First
                    a = 1;
                    b = 2;
                }
                else if (a == 1 || b == 2)
                {
                    //If this is 4th interval - set trip
                    if (a == -1)
                    {
                        trip = 1;
                    }

                    //a=-1 b=-2 Second OR a=1 b=-2 Fourth
                    a = -a;
                    b = -b;
                }
                else
                {
                    //a=-1 b=2 Third
                    b = -b;
                }

                //Adds values if they are within the board parameters
                int Xa = PosX + a;
                int Yb = PosY + b;
                if (Xa < 8 && Xa > 0 && Yb < 8 && Yb > 0)
                {
                    PossibleMoves.Add(new int[] { Xa, Yb });
                }

                int Xb = PosX + b;
                int Ya = PosY + a;
                if (Xb < 8 && Xb > 0 && Ya < 8 && Ya > 0)
                {
                    PossibleMoves.Add(new int[] { Xb, Ya });
                }

                b = b + trip;
            }

            //Check
            WriteLine("Rook Moves total: " + PossibleMoves.Count);

            //Send Moves
            return(PossibleMoves);
        }
Exemple #4
0
    private static float max(Board board, int depth, float alpha, float beta)
    {
        if (depth <= 0)
        {
            return(board.getValue(isWhite));
        }
        float  maxValue = -10000000;
        string pieces   = board.getPieces();

        for (int i = 0; i < pieces.Length; i++)
        {
            if ((board.isWhitesTurn() && char.IsUpper(pieces[i])) || (!board.isWhitesTurn() && char.IsLower(pieces[i])))
            {
                string square = letters[i % 9] + "" + (8 - i / 9);
                foreach (string move in PossibleMoves.search(board, square))
                {
                    string fen = board.fen;
                    board.movePiece(square, move);
                    maxValue = Mathf.Max(maxValue, max(board, depth - 1, alpha, beta));
                    alpha    = Mathf.Max(alpha, maxValue);
                    if (beta <= alpha)
                    {
                        return(maxValue);
                    }
                    board.fen = fen;
                }
            }
        }
        return(maxValue);
    }
Exemple #5
0
        private CellState[][] GetRefreshedField(PossibleMoves possibleMove, CellState[][] field, Team team)
        {
            var newField = Copy(field);

            foreach (var move in possibleMove.Moves)
            {
                var directionX = move.FromPoint.X < move.ToPoint.X ? 1 : -1;
                var directionY = move.FromPoint.Y < move.ToPoint.Y ? 1 : -1;

                var initialChecker = field[move.FromPoint.Y][move.FromPoint.X];

                var targetX = move.FromPoint.X;
                var targetY = move.FromPoint.Y;

                do
                {
                    newField[targetY][targetX] = CellState.EmptyCell;
                    targetX = (byte)(targetX + directionX);
                    targetY = (byte)(targetY + directionY);
                } while (targetY != move.ToPoint.Y && targetX != move.ToPoint.X);

                newField[move.ToPoint.Y][move.ToPoint.X] = initialChecker;
            }

            return(newField);
        }
Exemple #6
0
        public override void EliminateIllegalMoves()
        {
            PossibleMoves.RemoveAll(m => m.GetMovePos().ThreateningPieces.Any(p => p.PieceOwner != this.PieceOwner));

            foreach (var threateningPiece in _board[this.CurrentPosition].ThreateningPieces)
            {
                var tiles = threateningPiece.XRay(this);

                this.PossibleMoves.RemoveAll(m => tiles.Any(t => t.Position == m.GetMovePos().Position));
            }

            var castleMovesToRemove = new List <IMove>();

            foreach (var move in CastleMoves)
            {
                if (move.Value.Any(bt => bt.ThreateningPieces.Any(p => p.PieceOwner != this.PieceOwner)))
                {
                    castleMovesToRemove.Add(move.Key);
                }
            }

            foreach (var move in castleMovesToRemove)
            {
                CastleMoves.Remove(move);
            }
        }
        public void MyHandHasThreePossibleSameSuitMeld_GiveMeThatMeldAndTheDiscardMoves()
        {
            var cards = new[]
            {
                new Card(5, Suit.Hearts),
                new Card(10, Suit.Clubs),
                new Card(12, Suit.Spades),
                new Card(1, Suit.Diamonds),
                new Card(2, Suit.Diamonds),
                new Card(3, Suit.Diamonds),
                new Card(4, Suit.Diamonds),
                new Card(6, Suit.Diamonds)
            };
            GameState gs =
                CreateGamesStateWithPlayerOneHaving(cards, State.Player1MeldLayDiscard);

            var pa = new PossibleMoves(Player.One, gs);

            var moves = pa.Moves();

            Assert.AreEqual(11, moves.Count);

            CollectionAssert.Contains(moves,
                                      new MeldMove(Player.One,
                                                   new Meld(Suit.Diamonds, 1, 3)));
            CollectionAssert.Contains(moves,
                                      new MeldMove(Player.One,
                                                   new Meld(Suit.Diamonds, 2, 3)));
            CollectionAssert.Contains(moves,
                                      new MeldMove(Player.One,
                                                   new Meld(Suit.Diamonds, 1, 4)));
        }
        public void MyHandHasTwoPossibleLayOff_GiveMeThatLayOffsAndTheDiscardMoves()
        {
            var cards = new[]
            {
                new Card(6, Suit.Clubs),
                new Card(10, Suit.Clubs),
                new Card(12, Suit.Spades)
            };

            List <Meld> playerOneMelds = new List <Meld>();
            Meld        m = new Meld(Suit.Clubs, 7, 3);

            playerOneMelds.Add(m);

            GameState gs = CreateGamesStateWithPlayerOneHavingCardsAndMelds(cards, playerOneMelds, State.Player1MeldLayDiscard);

            var pa = new PossibleMoves(Player.One, gs);

            var moves = pa.Moves();

            Assert.AreEqual(5, moves.Count);

            CollectionAssert.Contains(moves,
                                      new LayOffMove(Player.One, new Card(10, Suit.Clubs), m));

            CollectionAssert.Contains(moves,
                                      new LayOffMove(Player.One, new Card(6, Suit.Clubs), m));
        }
Exemple #9
0
        //Method to Gather moves
        List <int[]> gatherMoves()
        {
            int[] currPos = { PosX, PosY };

            //Single dimensional movement is free (so long as space is not occupied)
            for (int i = 1; i <= 8 - PosX; i++)
            {
                PossibleMoves.Add(new int[] { PosX + i, PosY });
            }
            for (int i = 1; i <= 8 - PosY; i++)
            {
                PossibleMoves.Add(new int[] { PosX, PosY + i });
            }

            //As is negative movement
            for (int i = -1; i >= PosX - 8; i--)
            {
                PossibleMoves.Add(new int[] { PosX + i, PosY });
            }
            for (int i = -1; i >= PosY - 8; i--)
            {
                PossibleMoves.Add(new int[] { PosX, PosY + i });
            }


            //Check
            WriteLine("Rook Moves total: " + PossibleMoves.Count);

            //Send Moves
            return(PossibleMoves);
        }
        public void MyHandHasOnePossibleSameRankMeld_GiveMeThatMeldAndTheDiscardMoves()
        {
            var cards = new[]
            {
                new Card(1, Suit.Clubs), new Card(1, Suit.Diamonds),
                new Card(3, Suit.Diamonds), new Card(1, Suit.Spades)
            };
            GameState gs =
                CreateGamesStateWithPlayerOneHaving(cards, State.Player1MeldLayDiscard);

            var pa = new PossibleMoves(Player.One, gs);

            var moves = pa.Moves();

            Assert.AreEqual(5, moves.Count);

            CollectionAssert.Contains(moves, new DiscardMove(Player.One, cards[0]));
            CollectionAssert.Contains(moves, new DiscardMove(Player.One, cards[1]));
            CollectionAssert.Contains(moves, new DiscardMove(Player.One, cards[2]));
            CollectionAssert.Contains(moves, new DiscardMove(Player.One, cards[3]));

            CollectionAssert.Contains(moves,
                                      new MeldMove(Player.One,
                                                   new Meld(new[] { Suit.Clubs, Suit.Diamonds, Suit.Spades }, 1)));
        }
    /// <summary>
    /// Tries to move Pawn that belongs to CurrentPlayer from Band (if any).
    /// </summary>
    /// <returns>Whether we should skip player's turn (because he has pawns on band) or not.
    protected bool MovePawnFromBand()
    {
        if (Band)
        {
            bool bKeepTrying      = false;
            bool bBandHasPawns    = false;
            bool bIsDiceAvailable = false;
            do
            {
                bBandHasPawns    = Band.HasPawns(CurrentPlayer);
                bIsDiceAvailable = IsDiceAvailable();
                bKeepTrying      = bBandHasPawns && bIsDiceAvailable;

                if (bKeepTrying)
                {
                    // Since we're here, it means that there are our pawns on Band
                    // and dices still can be used for moves.

                    // Trying to find new moves that start from Band
                    PossibleMoves = new PossibleMoves(this, Band, Dices, true);

                    // If we found any moves, we can do first one.
                    if (PossibleMoves.HasAnyMoves())
                    {
                        // Doing first available move, we've found
                        PossibleMoves.DoFirstMove();

                        // bKeepTrying is already set to true,
                        // so we don't need to do with it anything else
                        // as we want to repeat whole process remove all
                        // our pawns from Band
                    }
                    else
                    {
                        // If we reached this place, it means that the we still
                        // have at least one pawn placed on the Band. Since we
                        // couldn't move it (had no possible moves) we have to skip
                        // our turn according to backgammon rules.

                        bKeepTrying = false;
                    }
                }
            }while (bKeepTrying);

            bBandHasPawns    = Band.HasPawns(CurrentPlayer);
            bIsDiceAvailable = IsDiceAvailable();

            if (bBandHasPawns || !bIsDiceAvailable)
            {
                return(true);
            }
        }
        else
        {
            Logger.Error(this, "Couldn't move pawns from Band because reference to it is null.");
        }

        return(false);
    }
        public async Task ApplyMove(BoardPosition position)
        {
            try
            {
                String path = @"C:\Users\Nick\Documents\TimeWithAlphaBeta.txt";

                var possMoves = mBoard.GetPossibleMoves() as IEnumerable <OthelloMove>;
                foreach (var move in possMoves)
                {
                    if (move.Position.Equals(position))
                    {
                        mBoard.ApplyMove(move);
                        break;
                    }
                }
                RebindState();

                if (Players == NumberOfPlayers.One && !mBoard.IsFinished)
                {
                    //Initialize Time
                    DateTime start = DateTime.Now;
                    DateTime end;

                    var bestMove = await Task.Run(() => mGameAi.FindBestMove(mBoard));

                    //Record finish time
                    end = DateTime.Now;

                    System.IO.File.AppendAllText(path, "Move " + (++mCount) + ": " + (end - start).ToString() + Environment.NewLine);
                    //file.WriteLine((end - start));

                    if (bestMove != null)
                    {
                        mBoard.ApplyMove(bestMove);
                        RebindState();
                    }
                }
            }

            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            if (mBoard.PassCount == 2)
            {
                GameFinished?.Invoke(this, new EventArgs());
            }

            if (PossibleMoves.Count == 1 && PossibleMoves.First().Row == -1)
            {
                CurrentPlayerMustPass?.Invoke(this, new EventArgs());
            }

            if (PossibleMoves.Count == 0 || mBoard.IsFinished)
            {
                GameFinished?.Invoke(this, new EventArgs());
            }
        }
Exemple #13
0
        public HumanPlayer(string playerName, IUserInterface userInterface)
        {
            _userInterface = userInterface;

            var moveKeys = string.Join(',', PossibleMoves.Select(x => x.Key));

            _askForInputtext = $"{playerName} input ({moveKeys}):";
        }
        public IMove GetMove()
        {
            var currentMove = _nextMove;

            _userInterface.Display($"{_playerName}:{currentMove.Key}");
            _nextMove = PossibleMoves.Single(x => x.Beats(currentMove));
            return(currentMove);
        }
Exemple #15
0
 private void SetCurrentMove(PossibleMoves currentMove, int x, int y)
 {
     if (SetCurrentMove(currentMove))
     {
         _50437079C366407D978Fe4Afd60C535F.MoveDestinationX = x;
         _50437079C366407D978Fe4Afd60C535F.MoveDestinationY = y;
     }
 }
Exemple #16
0
 public void ShowPossibleMoves(Piece piece)
 {
     foreach (var move in CalcPossibleMoves(piece))
     {
         move.End.IsPossibileSquare = true;
         PossibleMoves.Add(move);
     }
 }
Exemple #17
0
    public override void findPossibleMoves() //can move along file or rank, as long as it is not blocked
    {
        PossibleMoves.Clear();
        Coordinate   pTmp = new Coordinate(Position);
        string       color;
        Action <int> checkFile = (direction) =>
        {
            pTmp = new Coordinate(Position);
            for (; pTmp.changeFile(direction);)
            {
                color = board.CheckColor(pTmp);
                if (color == "none") //no piece, continue normally
                {
                    PossibleMoves.Add(pTmp);
                }
                else if (color != Color) //opposite piece, add its position and stop
                {
                    PossibleMoves.Add(pTmp);
                    break;
                }
                else //same color piece, don't add and stop
                {
                    break;
                }
                pTmp = new Coordinate(pTmp);
            }
            pTmp = new Coordinate(Position); //new coordinate object, resets position as well
        };
        Action <int> checkRank = (direction) =>
        {
            pTmp = new Coordinate(Position);
            for (; pTmp.changeRank(direction);)
            {
                color = board.CheckColor(pTmp);
                if (color == Color)
                {
                    break;
                }
                else if (color == "none")
                {
                    PossibleMoves.Add(pTmp);
                    pTmp = new Coordinate(pTmp);
                }
                else //opposite piece, add its position and stop
                { //bug occurs somewhere here, goes one position further than it should, or perhaps even past
                    PossibleMoves.Add(pTmp);
                    Console.WriteLine("Ocuured attempting position " + pTmp);
                    break;
                }
            }
            pTmp = new Coordinate(Position); //new coordinate object, resets position as well
        };

        checkFile(1);  //check right
        checkFile(-1); //check left
        checkRank(1);  //check up
        checkRank(-1); //check down
    }
Exemple #18
0
        public RandomAICardsController(IGameUIServices uiServices, FanCanvas shape, GameState gameState, Player player)
            : base(uiServices, shape, gameState, player, false)
        {
            AutoPlay = true;

            possibleMoves           = new PossibleMoves(player, gameState);
            gameState.MoveHappened += gameState_PlayerActed;

            InitMoveSelectorsPriorityList();
        }
Exemple #19
0
        private bool SetCurrentMove(PossibleMoves currentMove)
        {
            if (_50437079C366407D978Fe4Afd60C535F.CurrentMove == PossibleMoves.Idling)
            {
                _50437079C366407D978Fe4Afd60C535F.CurrentMove = currentMove;
                return(true);
            }

            return(false);
        }
Exemple #20
0
        public void getPossibleMoves(string playerDir, string enemyDir, string[] playerExpected, string[] enemyExpected, string rawBoard)
        {
            List <string> playerExpectedList = playerExpected.ToList();
            List <string> enemyExpectedList  = enemyExpected.ToList();
            Board         b = SnakeTestUtils.generateBoard(rawBoard, playerDir, enemyDir);
            PossibleMoves m = SnakeAPILogic.getPossibleMoves(b);

            Assert.True(SnakeTestUtils.comparePossibleMoves(m.playerMoves, playerExpectedList));
            Assert.True(SnakeTestUtils.comparePossibleMoves(m.enemyMoves, enemyExpectedList));
        }
        public void MoveComparer_Compare_Turning_To_Walking_Should_Return_Negative(PossibleMoves turning, PossibleMoves walking)
        {
            // Arrange
            var moveComparer = new MoveComparer();

            // Act
            var result = moveComparer.Compare(turning, walking);

            // Assert
            result.Should().BePositive();
        }
Exemple #22
0
    public bool isCheck(char king)
    {
        string pieces  = getPieces();
        string kingPos = letters[pieces.IndexOf(king) % 9] + "" + (8 - pieces.IndexOf(king) / 9);

        if (PossibleMoves.isAttacked(this, kingPos))
        {
            return(true);
        }
        return(false);
    }
Exemple #23
0
    public override void findPossibleMoves() //move forward one, direction dependent on color. can also capture diagonally
    {
        PossibleMoves.Clear();
        int direction = 0;

        if (Color == "white")
        {
            direction = 1;
        }
        else if (Color == "black")
        {
            direction = -1;
        }
        Coordinate mPosition = new Coordinate(Position); //creates a duplicate of pawn's position

        mPosition.changeRank(direction);                 //to check one in front of the pawn

        string front = board.CheckColor(mPosition);

        if (front == "none") //has opposite colored piece or no piece
        {
            PossibleMoves.Add(mPosition);
            if (hasMoved == false) //can move two spaces up if it has not yet moved and there is no piece already in front of it
            {
                mPosition = new Coordinate(mPosition);
                mPosition.changeRank(direction);
                if (board.CheckColor(mPosition) == "none")
                {
                    PossibleMoves.Add(mPosition);
                }
            }
        }
        mPosition = new Coordinate(Position);


        mPosition.changeRank(direction);
        if (mPosition.changeFile(1))        //checks in front and to the right of the pawn
        {
            if (isOppositeColor(mPosition)) //must have an opposite colored piece
            {
                PossibleMoves.Add(mPosition);
            }
        }

        mPosition = new Coordinate(Position);
        mPosition.changeRank(direction);
        if (mPosition.changeFile(-1)) //checks in front and to the left of the pawn
        {
            if (isOppositeColor(mPosition))
            {
                PossibleMoves.Add(mPosition);
            }
        }
    }
        public void MoveComparer_Compare_Identical_PossibleMoves_Should_Return_Zero(PossibleMoves move)
        {
            // Arrange
            var moveComparer = new MoveComparer();

            // Act
            var result = moveComparer.Compare(move, move);

            // Assert
            result.Should().BeZero();
        }
Exemple #25
0
        public GameState PickAMove(Move move)
        {
            if (!PossibleMoves.Contains(move))
            {
                throw new System.Exception("Can't play an impossible move: " + move);
            }

            var newBoard = m_board.SetCellOwner(CurrentPlayer, move.Target);

            return(new GameState(CurrentPlayer.Other, newBoard));
        }
Exemple #26
0
        public override void Sorcery(ref Cell[,] gameBoard)
        {
            Logic.DetermineUsableCells(CellTypes.Player2, CellTypes.Player1);
            GetPossibleMoves(gameBoard, ref PossibleMoves);
            Cell selected = GetRandomCell();

            if (selected != null)
            {
                gameBoard[selected.Y, selected.X].Type = CellTypes.Selected;
            }
            PossibleMoves.Clear();
        }
 public ProceduralPathArrow()
 {
     prevArrow = null;
     nextArrow = null;
     PossibleMoves = new PossibleMoves
     {
         Up = true,
         Down = true,
         Left = true,
         Right = true
     };
 }
 public Warrior(MapCoordinates position, int team, string name)
 {
     Hp                = 20;
     AttackRange       = 1;
     AttackStrength    = 5;
     CollisionStrength = 5;
     AttackRange       = 1;
     ActualPosition    = position;
     this.Team         = team;
     MaxSteps          = 2;
     UiPlannedMoves    = new PossibleMoves[MaxSteps];
     Name              = name;
 }
Exemple #29
0
        private void CheckAndSetPossibleMoves(MoveDirection direction, int stepsX, int stepsY, bool inBetweenSteps, int iterationX = 1, int iterationY = 1)
        {
            Board board = Scene.GetObject <Board>();

            if (board == null)
            {
                throw new NullReferenceException("No board found");
            }

            if (!inBetweenSteps)
            {
                iterationX = stepsX;
                iterationY = stepsY;
            }

            int side = ControllingUnit == ControllingUnit.Human ? -1 : 1;

            int left  = Convert.ToInt32(((direction & MoveDirection.Left) == MoveDirection.Left)) * iterationX;
            int right = Convert.ToInt32(((direction & MoveDirection.Right) == MoveDirection.Right)) * iterationX * -1;
            int up    = Convert.ToInt32(((direction & MoveDirection.Up) == MoveDirection.Up)) * iterationY * side;
            int down  = Convert.ToInt32(((direction & MoveDirection.Down) == MoveDirection.Down)) * iterationY * side * -1;

            int  x          = (CurrentNode.Xindex + left + right);
            int  y          = (CurrentNode.Yindex + up + down);
            bool markForAdd = false;

            if (board.Nodes.IsInBounds(x, y))
            {
                Node newNode = board.Nodes[x, y];
                if (newNode.IsFree)
                {
                    markForAdd = true;
                }
                else
                {
                    if (newNode.Piece.ControllingUnit != ControllingUnit)
                    {
                        markForAdd = true;
                    }
                }
            }

            if (markForAdd)
            {
                PossibleMoves.Add(board.Nodes[x, y]);
                if ((iterationX < stepsX || stepsX == 0) && (iterationY < stepsY || stepsY == 0))
                {
                    CheckAndSetPossibleMoves(direction, stepsX, stepsY, inBetweenSteps, ++iterationX, ++iterationY);
                }
            }
        }
Exemple #30
0
        public void RecursiveMovesGet(Board board, int position, int direction)
        {
            int pieceColor = 0;

            if (Color == "white")
            {
                pieceColor = 1;
            }
            else
            {
                pieceColor = -1;
            }
            //first handle out of bounds
            if (!(board.OutOfBoundsArea.ToList().IndexOf(position + direction * pieceColor * -1) != -1))
            {
                //now that we know not out of bounds let's try each way the piece moves over and over until we are either out of bounds or blocked or a capture is possible
                //Are we blocked?
                if (board.Pieces[position + direction * pieceColor * -1] == null)
                {
                    //okay we're not blocked
                    if (isLegalMove((direction * pieceColor * -1) + position, board, pieceColor))
                    {
                        PossibleMoves.Add((direction * pieceColor * -1) + position);
                        RecursiveMovesGet(board, -1 * pieceColor * (direction) + position, (direction));
                    }
                    else
                    {
                        return;
                    }
                }
                else if (board.Pieces[position + direction * pieceColor * -1] != null)
                {
                    //okay we're blocked, but is the block an enemy piece?
                    if (board.Pieces[position + direction * pieceColor * -1].Color != Color && board.Pieces[position + direction * pieceColor * -1].Color != null)
                    {
                        if (isLegalMove((direction * pieceColor * -1) + position, board, pieceColor))
                        {
                            PossibleMoves.Add((direction * pieceColor * -1) + position);
                        }
                    }
                    return;
                }
            }
            else
            {
                return;
            }

            //return new List<int>();
        }
Exemple #31
0
        static List <MoveScore> CalcMoveFreeDegs(SnakeBoard board)
        {
            PossibleMoves    possMoves = game.GetPossibleMoves(board);
            List <MoveScore> moves     = new List <MoveScore>(3);

            foreach (string direction in possMoves.playerMoves)
            {
                moves.Add(new MoveScore()
                {
                    dir = direction, score = DegreesOfFreedom(board, direction)
                });
            }
            return(moves);
        }