Esempio n. 1
0
 // Create any kind of move except set attribute
 internal static MovePartModel Create(MoveKinds kind, PlayerValue player, PositionValue position, PieceValue piece,
                                      PositionValue final = null)
 {
     return(new MovePartModel {
         Kind = kind, Player = player, Piece = piece, Position = position, Final = final,
     });
 }
Esempio n. 2
0
        // create all drops and moves for piece, position and board
        // checks movetype restriction if supplied, but Any means any
        // CHECK: I thought this was the way it used to be???
        // checks position or zone restriction by peeking into movegen
        internal IEnumerable <MoveModel> CreateMoves(MoveKinds kind, PieceValue piece, PositionValue position,
                                                     BoardModel board, MoveTypeValue movetype)
        {
            var movegens = (movetype == MoveTypeValue.Any) ? _movegens.Values.SelectMany(m => m)
        : _movegens.SafeLookup(movetype);

            if (movegens == null)
            {
                yield break;
            }
            foreach (var movegen in movegens)
            {
                var ok = (kind == MoveKinds.Move || movegen.PosOrZone.IsNull);
                if (!ok)
                {
                    var posorzone = movegen.PosOrZone.Value as PositionOrZone;
                    ok = (posorzone.IsPosition) ? (position == posorzone.Position)
            : board.InZone(posorzone.Zone, position);
                }
                if (ok)
                {
                    Logger.WriteLine(4, "CreateMoves {0} piece:{1} position:{2} movetype:{3}", kind, piece, position, movetype);
                    foreach (var move in movegen.Exec(kind, piece, position, board))
                    {
                        yield return(move);
                    }
                }
            }
            // TODO: after each Exec if the partial flag is set, add any possible further moves
            // (perhaps of a specific move type)
        }
Esempio n. 3
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);
 }
Esempio n. 4
0
 internal static MoveGenState Create(MoveKinds kind, PieceValue piece, PositionValue position, BoardModel board)
 {
     //internal static MoveGenState Create(MoveKinds kind, PlayerValue turnplayer, PlayerValue asplayer, PieceValue piece, PositionValue position) {
     return(new MoveGenState {
         _board = board, Kind = kind, Position = position, Piece = piece,
         Current = position, Mark = position,
     }.Reset());
 }