-
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.
Cleaned up the second Board constructor and removed JSONBoard
- Loading branch information
Showing
5 changed files
with
57 additions
and
113 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 was deleted.
Oops, something went wrong.
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,20 +1,20 @@ | ||
package com.flaghacker.sttt.common | ||
|
||
enum class Player(val niceString: String) { | ||
PLAYER("X"), | ||
ENEMY("O"), | ||
NEUTRAL(" "); | ||
enum class Player(val char: Char) { | ||
PLAYER('X'), | ||
ENEMY('O'), | ||
NEUTRAL(' '); | ||
|
||
fun otherWithNeutral(): Player = if (this == NEUTRAL) NEUTRAL else this.other() | ||
fun other(): Player = when (this) { | ||
PLAYER -> ENEMY | ||
ENEMY -> PLAYER | ||
else -> throw IllegalArgumentException("player should be one of [PLAYER, ENEMY]; was " + this) | ||
else -> throw IllegalArgumentException("player should be one of [PLAYER, ENEMY]; was $this") | ||
} | ||
|
||
fun otherWithNeutral(): Player = if (this == NEUTRAL) NEUTRAL else this.other() | ||
|
||
companion object { | ||
fun fromNiceString(string: String) = Player.values().find { it.niceString == string } | ||
?: throw IllegalArgumentException("$string is not a valid Player") | ||
fun legalChar(char: Char) = values().any { it.char == char } | ||
fun fromChar(char: Char) = values().find { it.char == char } | ||
?: throw IllegalArgumentException("$char is not a valid Player") | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.