// 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) }
//--- sexpr api void s_MoveType(MoveTypeValue movetype) { _movetype = movetype; }
// 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()); }