internal static void Create(List<Move> moves, Field node, Move move, Direction direction) { Field near = node[direction]; if (near == null) return; Field far = near[direction]; if (far == null) return; if (node.CanUse() && near.CanFree() && far.CanFree()) { Append(moves, move, move.Create(node, near, far)); } }
internal bool Exists(Move move, Field near, Field far) { bool result = false; if (move.Hash == 0) { if (!CanMove(near, far)) throw new InvalidOperationException(); { Use(); near.Free(); far.Free(); } result = move.Update(board); { Free(); near.Use(); far.Use(); } return result; } return board.Exists(move.Hash); }
internal bool DoMove(Move move, Field near, Field far) { if (!CanMove(near, far)) return false; if (Use() && near.Free() && far.Free()) { board.DoMove(this, near, far, move); return true; } return false; }
internal bool CanUndoMove(Field near, Field far) { return CanFree() && near.CanUse() && far.CanUse(); }
private static IEnumerable<Move> Create(Field node, Move move) { List<Move> moves = new List<Move>(); Create(moves, node, move, Direction.Left); Create(moves, node, move, Direction.Top); Create(moves, node, move, Direction.Right); Create(moves, node, move, Direction.Bottom); return moves; }
internal void UndoMove(Field node, Field near, Field far, Move move) { //data.Remove(hash); empty.Add(node); empty.Remove(near); empty.Remove(far); history.UndoMove(move); }
internal void DoMove(Field node, Field near, Field far, Move move) { hashSet.Add(hash); empty.Remove(node); empty.Add(near); empty.Add(far); history.DoMove(move); }