/// <summary> /// Returns a boolean value whether specified state /// equals to the goal state of problem /// </summary> public bool IsGoalState(BoardState state) { return(Equals(state, GoalState)); }
public Problem() { _initialState = new BoardState().Initialize(); _actionsFunction = state => { var actions = new HashSet <Action>(); var emptyPos = 0; while (emptyPos < state.Slots.Length) { var slot = state.Slots[emptyPos]; if (slot.IsEmpty()) { break; } emptyPos++; } if (state.IsBlackBallAt(emptyPos - 1)) { actions.Add(new Action { BallToMove = state.Slots[emptyPos - 1].GetBall(), Direction = MoveDirection.ToRight, SourcePosition = emptyPos - 1, TargetPosition = emptyPos }); } if (state.IsBlackBallAt(emptyPos - 2)) { actions.Add(new Action { BallToMove = state.Slots[emptyPos - 2].GetBall(), Direction = MoveDirection.ToRightWithJump, SourcePosition = emptyPos - 2, TargetPosition = emptyPos }); } if (state.IsWhiteBallAt(emptyPos + 1)) { actions.Add(new Action { BallToMove = state.Slots[emptyPos + 1].GetBall(), Direction = MoveDirection.ToLeft, SourcePosition = emptyPos + 1, TargetPosition = emptyPos }); } if (state.IsWhiteBallAt(emptyPos + 2)) { actions.Add(new Action { BallToMove = state.Slots[emptyPos + 2].GetBall(), Direction = MoveDirection.ToLeftWithJump, SourcePosition = emptyPos + 2, TargetPosition = emptyPos }); } return(actions); }; _resultFunction = (state, action) => { var nextState = new BoardState(state); nextState.MoveBall(action); return(nextState); }; }
public SearchResult(bool?hasSolution, bool isCutOff, ReadOnlyCollection <Action> actions = null, BoardState finalState = null) { HasSolution = hasSolution; IsCutOff = isCutOff; Actions = actions; FinalState = finalState; }