private void _AddJumpToLocation(LegacyPegLocation loc, int toRow, int toCol)
        {
            if (loc.location.row == 2 && loc.location.col == 2 && toRow == 4 && toCol == 0)
            {
                return;
            }
            if (loc.location.row == 4 && loc.location.col == 0 && toRow == 2 && toCol == 2)
            {
                return;
            }

            if (loc.location.row == toRow && loc.location.col == toCol)
            {
                return;
            }

            LegacyPegMove move = new LegacyPegMove();

            move.fromLocation = loc;
            move.toLocation   = boardArray[toRow, toCol];

            LegacyPegHole temp = move.CalcMiddle();

            move.middleLocation = boardArray[temp.row, temp.col];
            loc.places_can_jump_to.Add(move);
        }
 private void TestAndAddJumpLocation(LegacyPegLocation origLoc, int row, int column)
 {
     if (TestBoardLocation(row, column))
     {
         AddJumpToLocation(origLoc, row, column);
     }
 }
        private void InitJumpLocationsForLoc(LegacyPegLocation loc)
        {
            int row = loc.location.row;

            TestRow(row, loc);
            TestRow(row - 2, loc);
            TestRow(row + 2, loc);
        }
 public void GetPossibleMoves(LegacyPegLocation loc, List <LegacyPegMove> moves)
 {
     foreach (LegacyPegMove move in loc.places_can_jump_to)
     {
         if (move.middleLocation.isValid && move.middleLocation.filled && !move.toLocation.filled)
         {
             moves.Add(move);
         }
     }
 }
        public void InitBoard()
        {
            boardArray = new LegacyPegLocation[5, 5];
            LegacyPegLocation temp = null;

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    temp          = new LegacyPegLocation();
                    temp.location = new LegacyPegHole(i, j);
                    switch (j)
                    {
                    case 0:
                        temp.isValid = true;
                        break;

                    case 1:
                        if (i > 0)
                        {
                            temp.isValid = true;
                        }
                        break;

                    case 2:
                        if (i > 1)
                        {
                            temp.isValid = true;
                        }
                        break;

                    case 3:
                        if (i > 2)
                        {
                            temp.isValid = true;
                        }
                        break;

                    case 4:
                        if (i > 3)
                        {
                            temp.isValid = true;
                        }
                        break;
                    }
                    if (temp.isValid)
                    {
                        temp.filled = true;
                    }
                    boardArray[i, j] = temp;
                }
            }

            InitJumpLocations();
        }
        private void TestRow(int row, LegacyPegLocation origLoc)
        {
            int column = origLoc.location.col - 2;

            TestAndAddJumpLocation(origLoc, row, column);

            column = origLoc.location.col + 2;
            TestAndAddJumpLocation(origLoc, row, column);

            column = origLoc.location.col;
            TestAndAddJumpLocation(origLoc, row, column);
        }
示例#7
0
        public List <LegacyPegMove> GetMovesOnBoard()
        {
            List <LegacyPegMove> moves = new List <LegacyPegMove>();

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    LegacyPegLocation loc = board.boardArray[i, j];
                    if (loc.isValid && loc.filled)
                    {
                        board.GetPossibleMoves(loc, moves);
                    }
                }
            }
            return(moves);
        }
 private void AddJumpToLocation(LegacyPegLocation loc, int row, int column)
 {
     _AddJumpToLocation(loc, row, column);
 }