public State CheckNextState(Piece piece, int x, int y, int xDir, int yDir, bool swap, IList <Piece> pieces) { if (piece.CheckCanPlace(_grid, x, y, xDir, yDir, swap)) { //final state if (pieces.Count == 0) { return(this); } piece.Place(_grid, x, y, xDir, yDir, swap); if (!IsPossibleGrid(_grid) || _optimizer.IsKnownState(_grid)) { piece.Reset(_grid, x, y, xDir, yDir, swap); return(null); } _optimizer.SetKnownState(_grid); var candidate = new State(pieces, _grid, _optimizer); var candidateState = candidate.GetWinningState(); if (candidateState != null) { return(candidateState); } piece.Reset(_grid, x, y, xDir, yDir, swap); } return(null); }