コード例 #1
0
        private static void SetHoleFilled(PegBoard board, int fromNumber, bool filled)
        {
            var hole = board.Holes.FirstOrDefault(x => x.Number == fromNumber);

            if (hole != null)
            {
                hole.Filled = filled;
            }
        }
コード例 #2
0
        private static void MakeMove(PegBoard board, HistoricalMove historicalMove)
        {
            var fromNumber   = Conversion.ConvertToHoleNumber(historicalMove.move.fromLocation);
            var toNumber     = Conversion.ConvertToHoleNumber(historicalMove.move.toLocation);
            var middleNumber = Conversion.ConvertToHoleNumber(historicalMove.move.middleLocation);

            SetHoleFilled(board, fromNumber, false);
            SetHoleFilled(board, toNumber, true);
            SetHoleFilled(board, middleNumber, false);
        }
コード例 #3
0
        public PegBoard Clone()
        {
            var temp = new PegBoard();

            foreach (var hole in Holes.Select((x, i) => new { x.Filled, Index = i }))
            {
                temp.Holes[hole.Index].Filled = hole.Filled;
            }
            return(temp);
        }
コード例 #4
0
        private static List <PegMoveWithBoard> GetPegMoveWithBoards(List <HistoricalMove> moves, PegBoard tempBoard)
        {
            var resultList = new List <PegMoveWithBoard>();

            foreach (HistoricalMove historicalMove in moves.OrderBy(x => x.order))
            {
                resultList.Add(new PegMoveWithBoard
                {
                    Move  = ConvertFromLegacy(historicalMove.move),
                    Board = tempBoard
                });

                tempBoard = tempBoard.Clone();
                MakeMove(tempBoard, historicalMove);
            }

            return(resultList);
        }