Skip to content

Instantly share code, notes, and snippets.

View pumpkincouture's full-sized avatar

Sylwia Bridges pumpkincouture

View GitHub Profile
public class ChoiceValidator {
public int validUserChoice(String userChoice, List<String> correctChoices) {
if (correctChoices.contains(userChoice)) {
return convertAnswerToInteger(userChoice);
}
return 0;
}
private int convertAnswerToInteger(String answer) {
public class InputCollector {
private List<Integer> gameValues = new ArrayList<>();
public void collectUserInput(List<Configurable> gameOptions) {
for (Configurable configurable : gameOptions) {
configurable.getConfigurationChoice();
gameValues.add(configurable.getDesiredGameOptions());
}
}
public class GameConfiguration {
private CommandLineInterface ui;
private BoardRules boardRules;
private Board board;
private GameParticipants player1;
private GameParticipants player2;
private List<GameParticipants> positionsOfPlayers;
private int boardSize;
public void validateBoardSizeChoice(String boardSizeChoice) {
- JavaTTT
- Boards
- Participants
-ai
*branch
*HardAi
*SimpleAi
-human
*Human
#Participant
# Tests for elevator floor requests and destinations
describe Elevator do
it 'has a list of floors to deliver people to' do
elevator = Elevator.new(1, 5)
elevator.service_floor(1, 'up')
elevator.destination(3)
elevator.service_floor(1, 'up')
elevator.destination(4)
describe Elevator do
it "it returns the current floor of the elevator" do
elevator = Elevator.new(1, 5)
elevator.service_floor(2, 'up')
elevator.destination(3)
expect(elevator.current_location).to eq(3)
end
end
(defn minimax-move [cells depth current-player]
(let [values (map vector (vec (board/find-open-spaces cells)) (vec (get-spaces cells current-player depth)))
]
(first (first (sort-by second > values)))))
(defn update-scores-list [cells depth current-player]
(zipmap (board/find-open-spaces cells) (get-spaces cells current-player depth)))
(defn get-move [cells depth current-player]
(update-scores-list cells depth current-player))
(defn ai-move [cells depth current-player]
(first (first (sort-by second > (get-move cells depth current-player)))))
#Starting Board, it's O's turn
1 | X | 3
---------
4 | 5 | X
---------
O | O | X
#Depth 1 Boards
(let [opponent (switch-players current-player cells)]
(cond
(= (board/winner? current-player opponent cells) "O") (- win depth)
(= (board/winner? current-player opponent cells) "X") (+ depth loss)
:else tie)))