Example #1
0
        private void GetPieceRecurse(BGMoveSet moveset, List <int> diceSeq, int[] myBoard, int[] theirBoard)
        {
            //This routine is called recursively for each di in a sequence 2 or 4 (if doubles)
            //each piece is tried and the highest scoring sequence is remembered
            List <BGPiece> pieces = new List <BGPiece>(); // a list of pieces each piece has an id a position

            int[] myBoard1    = new int[26];              //  declare an instance of the board
            int[] theirBoard1 = new int[26];
            int   i           = moveset.BGMoves.Count();  // move index
            int   f           = 0;                        // piece.Position
            int   t           = 0;                        // to
            int   d           = 0;                        // dice to use

            Array.Copy(myBoard, myBoard1, 26);
            Array.Copy(theirBoard, theirBoard1, 26); //  work with a copy of the board
            pieces = GetPieces(myBoard);             // create alist of pieces
            if (i < diceSeq.Count)                   //there is an unused di in the sequence
            {
                bool moveFound = false;
                foreach (var piece in pieces)
                {
                    f = piece.Position;
                    d = diceSeq[i];
                    t = (f - d) < 0 ? 0 : f - d;                        // 0 represents bearing off; less than zero indicates you can bear off
                    if (aBGRules.IsLegal(f, t, myBoard, theirBoard, d)) // if legal move
                    {
                        BGMove aBGMove = new BGMove();                  //              add the move to the list of moves
                        aBGMove.PieceID    = piece.PieceID;
                        aBGMove.FMove      = f;
                        aBGMove.TMove      = t;
                        aBGMove.Di         = d;
                        aBGMove.SeqOrder   = i;
                        aBGMove.CheckerHit = (theirBoard[25 - t] == 1 && t != 0) ? true : false;
                        moveset.BGMoves.Add(aBGMove);
                        BoardUpdate(myBoard1, theirBoard1, f, t);                 //     update board
                        GetPieceRecurse(moveset, diceSeq, myBoard1, theirBoard1); // get another move
                        Array.Copy(myBoard, myBoard1, 26);
                        Array.Copy(theirBoard, theirBoard1, 26);                  //  restore the board
                        moveset.BGMoves.RemoveAt(i);
                        moveFound = true;
                    }
                }
                if (moveFound == false)                                // if no move is found it could be the first dice is unusable and the second may be
                {
                    moveset.Score = ScoreBoard(myBoard1, theirBoard1); // nevertheless score the move so far and record it
                    if ((moveset.Score > bestMoveSet.Score && moveset.BGMoves.Count == bestMoveSet.BGMoves.Count) || moveset.BGMoves.Count > bestMoveSet.BGMoves.Count)
                    {                                                  // either the score is better or there's more  move.
                        bestMoveSet.Update(moveset);
                    }
                }
            }
            else
            {
                moveset.Score = ScoreBoard(myBoard1, theirBoard1); // at the end of each set, score the moves
                if (moveset.Score > bestMoveSet.Score)
                {
                    bestMoveSet.Update(moveset);
                }
            }
        }
Example #2
0
File: BGMove.cs Project: wdjong/BGC
 public BGMove(BGMove move)
 {
     MoveID     = move.MoveID;
     PieceID    = move.PieceID;
     FMove      = move.FMove;
     TMove      = move.TMove;
     Di         = move.Di;
     CheckerHit = move.CheckerHit;
     SeqOrder   = move.SeqOrder;
 }
Example #3
0
 public void Update(BGMoveSet moveSet)
 {
     BGMoves.Clear();
     Di1   = moveSet.Di1;
     Di2   = moveSet.Di2;
     Score = moveSet.Score;
     foreach (BGMove move in moveSet.BGMoves)
     {
         BGMove bestMove = new BGMove(move);
         BGMoves.Add(bestMove);
     }
 }