-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from briancorbinxyz/JDK23++
Jdk23++
- Loading branch information
Showing
75 changed files
with
4,856 additions
and
2,416 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,23 @@ | ||
package org.example; | ||
|
||
import java.io.Serializable; | ||
import java.security.SecureRandom; | ||
import java.util.random.RandomGenerator; | ||
import java.util.function.ToIntFunction; | ||
import org.example.bot.BotStrategy; | ||
|
||
/** | ||
* Represents a bot player in the game. The bot player uses a random number generator to make moves | ||
* on the game board. | ||
*/ | ||
public record BotPlayer(String playerMarker, RandomGenerator random) | ||
implements Player, Serializable { | ||
public record BotPlayer(ToIntFunction<GameState> strategyFunction) implements Player, Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
private static final long serialVersionUID = 1L; | ||
|
||
public BotPlayer(String playerMarker) { | ||
// OVER-ENGINEER: Cryptographically secure by default | ||
this(playerMarker, new SecureRandom()); | ||
} | ||
public BotPlayer() { | ||
this(BotStrategy.DEFAULT); | ||
} | ||
|
||
public String getPlayerMarker() { | ||
return playerMarker; | ||
} | ||
|
||
public int nextMove(GameBoard board) { | ||
int dimension = board.getDimension(); | ||
int location; | ||
do { | ||
location = random.nextInt(dimension * dimension); | ||
} while (!board.isValidMove(location)); | ||
return location; | ||
} | ||
@Override | ||
public int nextMove(GameState state) { | ||
return strategyFunction.applyAsInt(state); | ||
} | ||
} |
Oops, something went wrong.