feat - ✨ add game and rules
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
700d5e804e
commit
cc27518657
@ -0,0 +1,88 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Scheme
|
||||||
|
LastUpgradeVersion = "1420"
|
||||||
|
version = "1.3">
|
||||||
|
<BuildAction
|
||||||
|
parallelizeBuildables = "YES"
|
||||||
|
buildImplicitDependencies = "YES">
|
||||||
|
<BuildActionEntries>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "YES"
|
||||||
|
buildForArchiving = "YES"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "Model"
|
||||||
|
BuildableName = "Model"
|
||||||
|
BlueprintName = "Model"
|
||||||
|
ReferencedContainer = "container:">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildActionEntry>
|
||||||
|
</BuildActionEntries>
|
||||||
|
</BuildAction>
|
||||||
|
<TestAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
codeCoverageEnabled = "YES"
|
||||||
|
onlyGenerateCoverageForSpecifiedTargets = "YES">
|
||||||
|
<CodeCoverageTargets>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "Model"
|
||||||
|
BuildableName = "Model"
|
||||||
|
BlueprintName = "Model"
|
||||||
|
ReferencedContainer = "container:">
|
||||||
|
</BuildableReference>
|
||||||
|
</CodeCoverageTargets>
|
||||||
|
<Testables>
|
||||||
|
<TestableReference
|
||||||
|
skipped = "NO">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "ModelTests"
|
||||||
|
BuildableName = "ModelTests"
|
||||||
|
BlueprintName = "ModelTests"
|
||||||
|
ReferencedContainer = "container:">
|
||||||
|
</BuildableReference>
|
||||||
|
</TestableReference>
|
||||||
|
</Testables>
|
||||||
|
</TestAction>
|
||||||
|
<LaunchAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
launchStyle = "0"
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
debugDocumentVersioning = "YES"
|
||||||
|
debugServiceExtension = "internal"
|
||||||
|
allowLocationSimulation = "YES">
|
||||||
|
</LaunchAction>
|
||||||
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
savedToolIdentifier = ""
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
debugDocumentVersioning = "YES">
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "Model"
|
||||||
|
BuildableName = "Model"
|
||||||
|
BlueprintName = "Model"
|
||||||
|
ReferencedContainer = "container:">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
</ProfileAction>
|
||||||
|
<AnalyzeAction
|
||||||
|
buildConfiguration = "Debug">
|
||||||
|
</AnalyzeAction>
|
||||||
|
<ArchiveAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
revealArchiveInOrganizer = "YES">
|
||||||
|
</ArchiveAction>
|
||||||
|
</Scheme>
|
@ -0,0 +1,27 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
public class Game {
|
||||||
|
private var rules : Rules
|
||||||
|
|
||||||
|
private var board : Board?
|
||||||
|
|
||||||
|
private var players : [Player] = []
|
||||||
|
|
||||||
|
/// Initialize game with a rule
|
||||||
|
public init(rules: Rules) {
|
||||||
|
self.rules = rules
|
||||||
|
self.board = createBoard(rules: rules)
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
public func createBoard(rules: Rules) -> Board? {
|
||||||
|
Board(withNbRows: type(of: rules).nbRows, withNbColumns: type(of: rules).nbColumns) ?? nil
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
public func insertPiece(player: Player) {
|
||||||
|
var col = player.chooseColumn()
|
||||||
|
|
||||||
|
board?.insertPiece(id: player.id, column: col)
|
||||||
|
}
|
||||||
|
}
|
@ -1,21 +1,23 @@
|
|||||||
/// Cclassic rules of Connect 4 game
|
/// Cclassic rules of Connect 4 game
|
||||||
public class ClassicRules {
|
public class ClassicRules : Rules {
|
||||||
public static var nbRows: Int = 6
|
public static var nbRows: Int = 6
|
||||||
public static var nbColumns: Int = 7
|
public static var nbColumns: Int = 7
|
||||||
public static var nbAlignedPieces: Int = 4
|
public static var nbAlignedPieces: Int = 4
|
||||||
public static var nbTrials: Int = 3
|
public static var nbTrials: Int = 3
|
||||||
|
|
||||||
public init() {}
|
public var winCoord : [(Int, Int)] = []
|
||||||
|
|
||||||
// public func createBoard() -> Board {
|
public func createBoard() -> Board? {
|
||||||
//
|
Board(withNbRows: Self.nbRows, withNbColumns: Self.nbColumns) ?? nil
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public func isGameOver() -> (Bool, Int, GameResult) {
|
///
|
||||||
// <#code#>
|
public func isGameOver() -> (Bool, Int, GameResult) {
|
||||||
// }
|
return (true, 2, .lose);
|
||||||
//
|
}
|
||||||
// public func getNextPlayer() -> Int {
|
|
||||||
// <#code#>
|
///
|
||||||
// }
|
public func getNextPlayer(board: Board) -> Int {
|
||||||
|
return 9;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
//
|
|
||||||
// HumanTests.swift
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Created by BREUIL Yohann on 11/02/2023.
|
|
||||||
//
|
|
||||||
|
|
||||||
import XCTest
|
|
||||||
|
|
||||||
final class HumanTests: XCTestCase {
|
|
||||||
|
|
||||||
override func setUpWithError() throws {
|
|
||||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tearDownWithError() throws {
|
|
||||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
|
||||||
}
|
|
||||||
|
|
||||||
func testExample() throws {
|
|
||||||
// This is an example of a functional test case.
|
|
||||||
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
||||||
// Any test you write for XCTest can be annotated as throws and async.
|
|
||||||
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
|
|
||||||
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
|
|
||||||
}
|
|
||||||
|
|
||||||
func testPerformanceExample() throws {
|
|
||||||
// This is an example of a performance test case.
|
|
||||||
self.measure {
|
|
||||||
// Put the code you want to measure the time of here.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,17 @@
|
|||||||
|
import XCTest
|
||||||
|
import Model
|
||||||
|
|
||||||
|
final class AITests: XCTestCase {
|
||||||
|
func testInit() {
|
||||||
|
func expect(nickname: String) {
|
||||||
|
let ai = AI()
|
||||||
|
|
||||||
|
XCTAssertEqual(ai.nickname, nickname)
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(nickname: "yobreuil")
|
||||||
|
expect(nickname: "cebouhou")
|
||||||
|
expect(nickname: "macheval")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
import XCTest
|
||||||
|
import Model
|
||||||
|
|
||||||
|
final class HumanTests: XCTestCase {
|
||||||
|
func testInit() {
|
||||||
|
func expect(nickname : String) {
|
||||||
|
func scan() -> Int { return 1 }
|
||||||
|
|
||||||
|
let human = Human(nickname: nickname, scanner: scan)
|
||||||
|
|
||||||
|
XCTAssertEqual(human.nickname, nickname)
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(nickname: "yobreuil")
|
||||||
|
expect(nickname: "cebouhou")
|
||||||
|
expect(nickname: "macheval")
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
import XCTest
|
||||||
|
import Model
|
||||||
|
|
||||||
|
final class ClassicRulesTests: XCTestCase {
|
||||||
|
func testStaticValues() {
|
||||||
|
XCTAssertEqual(6, ClassicRules.nbRows)
|
||||||
|
XCTAssertEqual(7, ClassicRules.nbColumns)
|
||||||
|
XCTAssertEqual(4, ClassicRules.nbAlignedPieces)
|
||||||
|
XCTAssertEqual(3, ClassicRules.nbTrials)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue