This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - JavaTTT | |
| - Boards | |
| - Participants | |
| -ai | |
| *branch | |
| *HardAi | |
| *SimpleAi | |
| -human | |
| *Human | |
| #Participant |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Starting Board, it's O's turn | |
| 1 | X | 3 | |
| --------- | |
| 4 | 5 | X | |
| --------- | |
| O | O | X | |
| #Depth 1 Boards |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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))) |