parent
f1fab2ec5a
commit
f66d5fe3f3
@ -1,3 +1,3 @@
|
|||||||
public enum PieceType: CaseIterable, Sendable {
|
public enum PieceType: Equatable, CaseIterable, Sendable {
|
||||||
case A, B
|
case A, B
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,18 @@
|
|||||||
public class Player {
|
public class Player : Equatable {
|
||||||
public let name: String
|
public let name: String
|
||||||
|
public let piece_type: PieceType
|
||||||
|
|
||||||
init(name: String) {
|
public init(name: String, piece_type: PieceType) {
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.piece_type = piece_type
|
||||||
}
|
}
|
||||||
|
|
||||||
public func chooseMove(allowed_moves moves: [Move.Action], board: Board) -> Move.Action {
|
public func chooseMove(allowed_moves moves: [Move.Action], board: Board) -> Move.Action {
|
||||||
fatalError("abstract method not implemented")
|
fatalError("abstract method not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static func == (lhs: Player, rhs: Player) -> Bool {
|
||||||
|
// TODO: name equality or reference equality?
|
||||||
|
lhs === rhs
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
import XCTest
|
||||||
|
@testable import Model
|
||||||
|
|
||||||
|
final class HumanPlayerTests: XCTestCase {
|
||||||
|
func testInit() {
|
||||||
|
let p = HumanPlayer(name: "the name", piece_type: .B, callback: { _, _ in fatalError("NOOP") })
|
||||||
|
|
||||||
|
XCTAssertEqual(p.name, "the name")
|
||||||
|
XCTAssertEqual(p.piece_type, .B)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testChoose() {
|
||||||
|
let board = Board(columns: 3, rows: 3)!
|
||||||
|
let moves: [Move.Action] = [.InsertAt(where: Coords(1, 2)), .InsertOnSide(side: .Left, offset: 1)]
|
||||||
|
|
||||||
|
let player = HumanPlayer(name: "name", piece_type: .A, callback: {
|
||||||
|
moves2, board2 in
|
||||||
|
|
||||||
|
XCTAssertEqual(moves2, moves)
|
||||||
|
XCTAssertEqual(board2, board)
|
||||||
|
|
||||||
|
return .InsertOnSide(side: .Bottom, offset: 99)
|
||||||
|
})
|
||||||
|
|
||||||
|
XCTAssertEqual(player.chooseMove(allowed_moves: moves, board: board), .InsertOnSide(side: .Bottom, offset: 99))
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
import XCTest
|
||||||
|
@testable import Model
|
||||||
|
|
||||||
|
final class RandomPlayerTests: XCTestCase {
|
||||||
|
func testInit() {
|
||||||
|
for t in [PieceType.A, .B] {
|
||||||
|
let p = RandomPlayer(name: "the name", piece_type: t)
|
||||||
|
|
||||||
|
XCTAssertEqual(p.name, "the name")
|
||||||
|
XCTAssertEqual(p.piece_type, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testChoose() {
|
||||||
|
let board = Board(columns: 3, rows: 3)!
|
||||||
|
let moves: [Move.Action] = [.InsertAt(where: Coords(1, 2)), .InsertOnSide(side: .Left, offset: 1)]
|
||||||
|
|
||||||
|
let player = RandomPlayer(name: "name", piece_type: .A)
|
||||||
|
|
||||||
|
// +5 test quality credits
|
||||||
|
for _ in 1...10 {
|
||||||
|
let choosen = player.chooseMove(allowed_moves: moves, board: board)
|
||||||
|
|
||||||
|
XCTAssertNotNil(moves.firstIndex(of: choosen))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue