parent
9690a2dcb1
commit
4b2052e2c0
@ -0,0 +1,7 @@
|
||||
import Connect4Persistance
|
||||
|
||||
extension Persistance {
|
||||
static let unfinishedGameFileName: String = "lastUnfinished.co4"
|
||||
static let finishedGameFileName: String = "savedGames.json"
|
||||
static let saveDirectory: String = "connect4.games"
|
||||
}
|
@ -1,7 +1,21 @@
|
||||
import Foundation
|
||||
import Connect4Core
|
||||
import Connect4Players
|
||||
|
||||
enum PlayerType: CaseIterable, Identifiable {
|
||||
var id: Self { self }
|
||||
|
||||
case Human, AIRandom, AIFinnishHim, AISimpleNegaMax
|
||||
}
|
||||
|
||||
extension Player {
|
||||
var type: PlayerType {
|
||||
switch (self) {
|
||||
case is HumanPlayer: .Human
|
||||
case is RandomPlayer: .AIRandom
|
||||
case is FinnishHimPlayer: .AIFinnishHim
|
||||
case is SimpleNegaMaxPlayer: .AISimpleNegaMax
|
||||
default: fatalError("Unexpected player type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,19 @@
|
||||
import Connect4Core
|
||||
import Connect4Rules
|
||||
|
||||
enum RulesType: CaseIterable, Identifiable {
|
||||
var id: Self { self }
|
||||
|
||||
case Classic, TicTacToe, PopOut
|
||||
}
|
||||
|
||||
extension Rules {
|
||||
var type: RulesType {
|
||||
switch (self) {
|
||||
case is Connect4Rules: .Classic
|
||||
case is TicTacToeRules: .TicTacToe
|
||||
case is PopOutRules: .PopOut
|
||||
default: fatalError("Unexpected rules type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
import Foundation
|
||||
|
||||
extension String {
|
||||
var nilIfEmpty: Self? {
|
||||
if self.isEmpty {
|
||||
nil
|
||||
} else {
|
||||
self
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue