diff --git a/4forces.xcworkspace/xcuserdata/yorickgeoffre.xcuserdatad/UserInterfaceState.xcuserstate b/4forces.xcworkspace/xcuserdata/yorickgeoffre.xcuserdatad/UserInterfaceState.xcuserstate index 5e5246a..c829ef8 100644 Binary files a/4forces.xcworkspace/xcuserdata/yorickgeoffre.xcuserdatad/UserInterfaceState.xcuserstate and b/4forces.xcworkspace/xcuserdata/yorickgeoffre.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/4forces.xcworkspace/xcuserdata/yorickgeoffre.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/4forces.xcworkspace/xcuserdata/yorickgeoffre.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 42a2763..ae40b44 100644 --- a/4forces.xcworkspace/xcuserdata/yorickgeoffre.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/4forces.xcworkspace/xcuserdata/yorickgeoffre.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -263,8 +263,8 @@ filePath = "forcesPack/Sources/forcesPack/Rules/AreRows4x.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "19" - endingLineNumber = "19" + startingLineNumber = "20" + endingLineNumber = "20" landmarkName = "isRuleMet(grid:targetedRow:targetedCol:)" landmarkType = "7"> @@ -359,8 +359,8 @@ filePath = "forcesPack/Sources/forcesPack/Rules/AreCols4x.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "11" - endingLineNumber = "11" + startingLineNumber = "12" + endingLineNumber = "12" landmarkName = "isRuleMet(grid:targetedRow:targetedCol:)" landmarkType = "7"> diff --git a/forcesPack/Sources/forcesPack/Game.swift b/forcesPack/Sources/forcesPack/Game.swift index dd9d9a0..a96598d 100644 --- a/forcesPack/Sources/forcesPack/Game.swift +++ b/forcesPack/Sources/forcesPack/Game.swift @@ -40,6 +40,10 @@ public class Game{ } } + public convenience init(_ test: Int){ + self.init([IA(id: 0), IA(id: 1)]) + } + private func doGameLoop() -> Bool{ for p in players{ while(!board.insertPeice(id: p.id, row: p.play(board.nbCols-1))){} diff --git a/forcesPack/Sources/forcesPack/Rules/AreCols4x.swift b/forcesPack/Sources/forcesPack/Rules/AreCols4x.swift index 506d65b..cf6cb96 100644 --- a/forcesPack/Sources/forcesPack/Rules/AreCols4x.swift +++ b/forcesPack/Sources/forcesPack/Rules/AreCols4x.swift @@ -6,8 +6,9 @@ // import Foundation -class AreCols4x: Rule{ //TODO: use the targeted row/col for more precision - func isRuleMet(grid: [[Int?]], targetedRow: Int, targetedCol: Int) -> Bool { +public class AreCols4x: Rule{ //TODO: use the targeted row/col for more precision + public init() {} + public func isRuleMet(grid: [[Int?]], targetedRow: Int, targetedCol: Int) -> Bool { // print("rule: cols") var i: Int = 0 var old: Int? = -1 diff --git a/forcesPack/Sources/forcesPack/Rules/AreDiags4x.swift b/forcesPack/Sources/forcesPack/Rules/AreDiags4x.swift index 06ae641..f1e7a9e 100644 --- a/forcesPack/Sources/forcesPack/Rules/AreDiags4x.swift +++ b/forcesPack/Sources/forcesPack/Rules/AreDiags4x.swift @@ -7,8 +7,9 @@ import Foundation -class AreDiags4x: Rule{ //TODO: use the targeted row/col for more precision - func isRuleMet(grid: [[Int?]], targetedRow: Int, targetedCol: Int) -> Bool { +public class AreDiags4x: Rule{ //TODO: use the targeted row/col for more precision + public init() {} + public func isRuleMet(grid: [[Int?]], targetedRow: Int, targetedCol: Int) -> Bool { let colRange = 0...grid.count-1 let rowRange = 0...grid[0].count-1 diff --git a/forcesPack/Sources/forcesPack/Rules/AreRows4x.swift b/forcesPack/Sources/forcesPack/Rules/AreRows4x.swift index 610540e..3f81b55 100644 --- a/forcesPack/Sources/forcesPack/Rules/AreRows4x.swift +++ b/forcesPack/Sources/forcesPack/Rules/AreRows4x.swift @@ -7,8 +7,9 @@ import Foundation -class AreRows4x: Rule{//TODO: use the targeted row/col for more precision - func isRuleMet(grid: [[Int?]], targetedRow: Int, targetedCol: Int) -> Bool { +public class AreRows4x: Rule{//TODO: use the targeted row/col for more precision + public init() {} + public func isRuleMet(grid: [[Int?]], targetedRow: Int, targetedCol: Int) -> Bool { // print("rule: rows") var i: [Int] = Array( repeating: 0, count: grid.count) var old: [Int?] = Array( repeating: nil, count: grid.count) diff --git a/forcesPack/Sources/forcesPack/Rules/Rule.swift b/forcesPack/Sources/forcesPack/Rules/Rule.swift index 4183299..79084d0 100644 --- a/forcesPack/Sources/forcesPack/Rules/Rule.swift +++ b/forcesPack/Sources/forcesPack/Rules/Rule.swift @@ -7,6 +7,6 @@ import Foundation -protocol Rule{ +public protocol Rule{ func isRuleMet(grid: [[Int?]], targetedRow: Int, targetedCol: Int)-> Bool } diff --git a/forcesPack/Sources/forcesPack/Rules/nbRowsRule.swift b/forcesPack/Sources/forcesPack/Rules/nbRowsRule.swift index ff9cda6..bd2fbfa 100644 --- a/forcesPack/Sources/forcesPack/Rules/nbRowsRule.swift +++ b/forcesPack/Sources/forcesPack/Rules/nbRowsRule.swift @@ -7,7 +7,7 @@ import Foundation -protocol nbRowsRule{ +public protocol nbRowsRule{ var maxRow: Int { get } var maxCol: Int { get } } diff --git a/forcesPack/Tests/forcesPackTests/GameTests.swift b/forcesPack/Tests/forcesPackTests/GameTests.swift new file mode 100644 index 0000000..68d9d10 --- /dev/null +++ b/forcesPack/Tests/forcesPackTests/GameTests.swift @@ -0,0 +1,16 @@ +// +// File.swift +// +// +// Created by yorick geoffre on 07/02/2023. +// + +import Foundation +import forcesPack +import XCTest + +final class GameTests: XCTestCase{ + public func testGame(){ + XCTAssertNoThrow(Game(-1)) + } +} diff --git a/forcesPack/Tests/forcesPackTests/PlayerTests.swift b/forcesPack/Tests/forcesPackTests/PlayerTests.swift index d705cd3..f14fcb7 100644 --- a/forcesPack/Tests/forcesPackTests/PlayerTests.swift +++ b/forcesPack/Tests/forcesPackTests/PlayerTests.swift @@ -26,5 +26,4 @@ final class PlayerTests: XCTestCase { XCTAssertNotNil(p) XCTAssertEqual(p.description, "Human 0") } - } diff --git a/forcesPack/Tests/forcesPackTests/boardRulesTests.swift b/forcesPack/Tests/forcesPackTests/boardRulesTests.swift index b177400..e8412b6 100644 --- a/forcesPack/Tests/forcesPackTests/boardRulesTests.swift +++ b/forcesPack/Tests/forcesPackTests/boardRulesTests.swift @@ -7,9 +7,34 @@ import Foundation import XCTest +import forcesPack final class BoardRulesTests: XCTestCase { + private var boardEmpty: [[Int?]] = [[nil,nil,nil,nil],[nil,nil,nil,nil],[nil,nil,nil,nil],[nil,nil,nil,nil]] + private var boardRow: [[Int?]] = [[0,0,0,0],[nil,nil,nil,nil],[nil,nil,nil,nil],[nil,nil,nil,nil]] + private var boardCol: [[Int?]] = [[0,nil,nil,nil],[0,nil,nil,nil],[0,nil,nil,nil],[0,nil,nil,nil]] + private var boardDiag: [[Int?]] = [[0,nil,nil,nil],[nil,0,nil,nil],[nil,nil,0,nil],[nil,nil,nil,0]] + func testRules(){ - //let rule : Rule + var ruleCol : Rule = AreCols4x() + var ruleRow: Rule = AreRows4x() + var ruleDiag: Rule = AreDiags4x() + + XCTAssertFalse(ruleCol.isRuleMet(grid: boardEmpty, targetedRow: 0, targetedCol: 0)) + XCTAssertFalse(ruleRow.isRuleMet(grid: boardEmpty, targetedRow: 0, targetedCol: 0)) + XCTAssertFalse(ruleDiag.isRuleMet(grid: boardEmpty, targetedRow: 0, targetedCol: 0)) + + XCTAssertTrue(ruleCol.isRuleMet(grid: boardRow, targetedRow: 0, targetedCol: 0)) + XCTAssertFalse(ruleRow.isRuleMet(grid: boardRow, targetedRow: 0, targetedCol: 0)) + XCTAssertFalse(ruleDiag.isRuleMet(grid: boardRow, targetedRow: 0, targetedCol: 0)) + + XCTAssertFalse(ruleCol.isRuleMet(grid: boardCol, targetedRow: 0, targetedCol: 0)) + XCTAssertTrue(ruleRow.isRuleMet(grid: boardCol, targetedRow: 0, targetedCol: 0)) + XCTAssertFalse(ruleDiag.isRuleMet(grid: boardCol, targetedRow: 0, targetedCol: 0)) + + + XCTAssertFalse(ruleCol.isRuleMet(grid: boardDiag, targetedRow: 0, targetedCol: 0)) + XCTAssertFalse(ruleRow.isRuleMet(grid: boardDiag, targetedRow: 0, targetedCol: 0)) + XCTAssertTrue(ruleDiag.isRuleMet(grid: boardDiag, targetedRow: 0, targetedCol: 0)) } }