Exemple #1
0
 internal bool Exec(BoardModel board, bool phase2)
 {
     _board  = board;
     _phase1 = !phase2;
     _phase2 = phase2;
     return((EvalExec() as BoolValue).Value);
 }
Exemple #2
0
 // create moves for this piece and position on this board
 internal IList <MoveModel> CreateMoves(PositionValue position, BoardModel board, MoveTypeValue movetype)
 {
     Logger.WriteLine(5, "Create moves piece:{0} position:{1}", _piecedef.Piece, position);
     return(_movecodes
            .SelectMany(c => c.CreateMoves(MoveKinds.Move, _piecedef.Piece, position, board, movetype))
            .ToList());
 }
Exemple #3
0
 // Generate drops for current player for all pieces
 // use all pieces that have moves defined (check off store later) and all positions on the board
 // TODO: only do drops for pieces with offstore > 0?
 internal IList <MoveModel> CreateDrops(BoardModel board)
 {
     return(_piececodes
            .SelectMany(p => board.Def.PositionLookup.Keys
                        .SelectMany(q => p.Value.CreateDrops(q, board, board.Turn.MoveType)))
            .ToList());
 }
Exemple #4
0
 // main entry point for generating moves for player, piece and position
 // note that a gencode block can contain multiple sections and generate multiple moves for the position
 // CHECK: the state block persists and must be reinitialised
 internal IList <MoveModel> Exec(MoveKinds kind, PieceValue piece, PositionValue position, BoardModel board)
 {
     _board = board;
     _state = MoveGenState.Create(kind, piece, position, board);
     EvalExec();
     return(_state.MoveList);
 }
Exemple #5
0
 //-- factories
 internal static ChoiceMaker Create(BoardModel board, ChooserKinds kind, int steps, int depth)
 {
     return(new ChoiceMaker {
         _choice = Choice.Create(board),
         _kind = kind,
         StepCount = steps,
         MaxDepth = depth,
     });
 }
Exemple #6
0
        // Generate moves for all pieces on board for this player
        // use pieces only for this player, only if moves defined, and current position on the board
        internal IList <MoveModel> CreateMoves(BoardModel board)
        {
            var player = board.MovePlayer;

            return(board.PlayedPieceLookup
                   .Where(p => p.Value.Player == player)
                   .Where(p => _piececodes.ContainsKey(p.Value.Piece))
                   .SelectMany(p => _piececodes[p.Value.Piece].CreateMoves(p.Key, board, board.Turn.MoveType))
                   .ToList());
        }
Exemple #7
0
 //-- factories
 static internal Choice Create(BoardModel board)
 {
     return(new Choice {
         Board = board,
         IsDone = board.HasResult,
         Weight = 0,
         BestIndex = -1, // invalid until set
         VisitCount = 0,
         WinCount = 0,
         Children = new Choice[board.LegalMoves.Count],
     });
 }
Exemple #8
0
 // check goal conditions for current player to see if game has ended and how
 internal ResultKinds CheckCondition(GoalDef goal, BoardModel board, bool phase2)
 {
     return(goal.Code.Exec(board, phase2) ? goal.Kind : ResultKinds.None);
 }
Exemple #9
0
 //-- methods
 // get weight for board resulting from last move
 internal static double GetWeight(BoardModel board)
 {
     return(-_weightlookup[board.MoveResult]);
 }