Ejemplo n.º 1
0
 // reset after Add
 MoveGenState Reset()
 {
     From  = Position;
     To    = null;
     _move = MoveModel.Create(TurnPlayer, Position, Piece);
     _changes.Clear();
     _captures.Clear();
     return(this);
 }
Ejemplo n.º 2
0
 // create new board by applying move to old one
 static BoardModel CreateMoved(BoardModel board, MoveModel move)
 {
     return(new BoardModel {
         _game = board._game,
         LastBoard = board,
         Def = board.Def,
         LastMove = move,
         LastTurn = board.Turn,
         _turnindex = board._turnindex + 1,
         _playedpieces = new Dictionary <PositionValue, PieceModel>(board._playedpieces),
         _offstores = new Dictionary <Pair <PlayerValue, PieceValue>, int>(board._offstores),
     }.ApplyMove(move).GenerateNewState());
 }
Ejemplo n.º 3
0
 // generate actual moves if not done already during condition checking
 // assumes CurrentPlayer set already
 internal void GenerateMoves()
 {
     if (!_donemovegen)
     {
         LegalMoves.AddRange(_game.CreateDrops(this));
         LegalMoves.AddRange(_game.CreateMoves(this));
         var passoption = _game.Def.GetProperty("pass turn") ?? OptionValue.False;
         var allowpass  = passoption.Equals(OptionValue.True) ||
                          (LegalMoves.Count == 0 && passoption.Equals(OptionValue.Forced));
         if (allowpass)
         {
             LegalMoves.Insert(0, MoveModel.Create(Turn.TurnPlayer, PositionValue.None, PieceValue.None));
         }
         _donemovegen = true;
     }
 }
Ejemplo n.º 4
0
        // privately apply move to copy of board
        BoardModel ApplyMove(MoveModel move)
        {
            foreach (var m in move.MoveParts)
            {
                switch (m.Kind)
                {
                case MoveKinds.Drop:
                    CheckCapture(m.Position);
                    _playedpieces[m.Position] = _game.CreatePiece(m.Player, m.Piece);
                    IncOffStore(m.Player, m.Piece, -1);
                    break;

                case MoveKinds.Copy:
                    CheckCapture(m.Final);
                    var ppc = _playedpieces[m.Position];
                    _playedpieces[m.Final] = (ppc.Piece == m.Piece) ? ppc : ppc.Create(m);
                    break;

                case MoveKinds.Move:
                    CheckCapture(m.Final);
                    var ppm = _playedpieces[m.Position];
                    _playedpieces[m.Final] = (ppm.Piece == m.Piece) ? ppm : ppm.Create(m);
                    if (m.Final != m.Position)
                    {
                        _playedpieces.Remove(m.Position);
                    }
                    break;

                case MoveKinds.Take:
                    CheckCapture(m.Position);
                    _playedpieces.Remove(m.Position);
                    break;

                case MoveKinds.Owner:
                case MoveKinds.Piece:
                case MoveKinds.Attrib:
                    _playedpieces[m.Position] = _playedpieces[m.Position].Create(m);
                    break;

                default:
                    throw Error.Assert("apply {0}", move);
                }
            }
            return(this);
        }