diff --git a/README.md b/README.md index e2f276b..9165558 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,4 @@ This will take a while (~ 20 minutes) to setup. Then, you can run the command: 8. At the due date, your fork will be cloned, and will be tested and looked through manually to ensure it is legit, and to give some human feedback on code structure. -Alex wuz here \ No newline at end of file +Alex wuz here diff --git a/Sources/KonaneColor.swift b/Sources/KonaneColor.swift index 9e9cfcb..c35d493 100644 --- a/Sources/KonaneColor.swift +++ b/Sources/KonaneColor.swift @@ -1,3 +1,5 @@ enum KonaneColor { - case black, white, empty + case black + case white + case empty } diff --git a/Sources/KonaneGame.swift b/Sources/KonaneGame.swift index ac4d205..0077cdb 100644 --- a/Sources/KonaneGame.swift +++ b/Sources/KonaneGame.swift @@ -1,96 +1,30 @@ class KonaneGame { - private let gameState: KonaneGameState = KonaneGameState() - private let blackInputSource: KonaneMoveInputSource - private let whiteInputSource: KonaneMoveInputSource - init(blackIsHuman: Bool, whiteIsHuman: Bool) { - if blackIsHuman { - blackInputSource = KonaneMoveInputSourceHuman(isBlack: true) + if blackIsHuman == false { + // Set input to AI source + fatalError("No AI yet") } else { - fatalError("Doesn't work yet!") + blackInputSource = KonaneMoveInputSourceHuman(isBlack: true) } - - if whiteIsHuman { - whiteInputSource = KonaneMoveInputSourceHuman(isBlack: false) + + if whiteIsHuman == false { + fatalError("No AI yet") } else { - fatalError("Doesn't work yet!") + whiteInputSource = KonaneMoveInputSourceHuman(isBlack: false) } + + } + private var gameState = KonaneGameState(height: 16, width: 16, isBlackTurn: true) + private let blackInputSource: KonaneMoveInputSource + private let whiteInputSource: KonaneMoveInputSource func play() -> Bool { - // Remove Phase - print("Black starts by removing a middle or corner black piece") - displayBoard() - - let blackRemovePoint = blackInputSource.removeFirstPiece(gameState: gameState.copy()) - gameState.perform(blackRemove: blackRemovePoint) - - print("Now white removes an adjacent white piece") - displayBoard() - - let whiteRemovePoint = whiteInputSource.removeSecondPiece(gameState: gameState.copy()) - gameState.perform(whiteRemove: whiteRemovePoint) - - // Now, main game loop - while gameState.didBlackWin() == false && gameState.didWhiteWin() == false { - - let move: KonaneMove - if gameState.getIsBlackTurn() { - print("It is black's turn to jump") - displayBoard() - move = blackInputSource.nextMove(gameState: gameState.copy()) - } else { - print("It is white's turn to jump") - displayBoard() - move = whiteInputSource.nextMove(gameState: gameState.copy()) - } - - gameState.perform(move: move) - } - - let blackWins = gameState.didBlackWin() - if blackWins { - print("Black wins!") - } else { - print("White wins!") - } - return blackWins + // a bool saying `if its time to play or not } - + private func displayBoard() { - displayASCIIBoard() - } - - private func displayASCIIBoard() { - for y in (0.. KonaneGameState { - let c = KonaneGameState() - c.board = board - c.isBlackTurn = isBlackTurn - return c - } - - func getIsBlackTurn() -> Bool { - return isBlackTurn - } - - func color(atX: Int, atY: Int) -> KonaneColor { - return board[atX][atY] - } - - func isValid(move: KonaneMove) -> Bool { - print("Doesn't work yet") + private var InternalBoardDataStorage: [[KonaneColor]] + //getIsBlackTurn is a function that I'm calling print(color(atX: Int, atY:Int))*/ + //I think this is how to call a function with either print(function) or just saying the function with parameters but I'm not entirely sure + //Bottom left, 0-indexed are the following properties functions, cuz I'm not really sure... + + func isValid(move: KonaneMove) -> Bool{ + //check all rules to see if the move is valid. Also maybe change Bool to another type return true - } - - func isValid(blackRemove: (x: Int, y: Int)) -> Bool { - print("Doesn't work yet") + } + func isValid(blackRemove: (x: Int, y: Int)) -> Bool{ + // I think check rules to see if you can remove the piece and check if Bool is the right type to return return true } - - func isValid(whiteRemove: (x: Int, y: Int)) -> Bool { - print("Doesn't work yet") + func isValid(whiteRemove: (x: Int, y: Int)) -> Bool { return true } - - func perform(move: KonaneMove) { - print("Doesn't work yet!") - - isBlackTurn = !isBlackTurn - } - - func perform(blackRemove: (x: Int, y: Int)) { - var remove = blackRemove - if !isValid(blackRemove: remove) { - fatalError("Invalid black remove: \(remove)") - } + func perform(move: KonaneMove){ - board[remove.x][remove.y] = KonaneColor.empty } - - func perform(whiteRemove: (x: Int, y: Int)) { - var remove = whiteRemove - if !isValid(whiteRemove: remove) { - fatalError("Invalid white remove: \(remove)") - } - - board[remove.x][remove.y] = KonaneColor.empty + func perform(blackRemove: (x: Int, y: Int)) -> Int { + //YOU MIGHT HAVE TO RETURN A TUPLE ( is that what its called? when you return multiple return values) + let holdMyPlace = 6 + return holdMyPlace + //BOI THIS VALUE HAS NO VALUE SO GET RID OF IT!!! } - - func didBlackWin() -> Bool { - print("Doesn't work yet!") - return false + func perform(whiteRemove: (x: Int, y: Int)) -> Int { + // SAME DEAL AS PREFORM(BLACKREMOVE) YOU GOTTA REPLACE EVERYTHING!!!!!! + let placeMyHold = 7 + return placeMyHold } - - func didWhiteWin() -> Bool { - print("Doesn't work yet!") - return false + func didBlckWin() -> Bool { + // IS THIS RETURNED AS TRUE? I DONT KNOW YET SO FIX IT!!!! + return true } + func didWhiteWin() -> Bool { + // I DONT KNOW DID WHITE WIN? YOU DECIDE, BUT FIRST FIX THE CODE!!!! + return true + } + } diff --git a/Sources/KonaneMove.swift b/Sources/KonaneMove.swift index 610e0f9..15862fc 100644 --- a/Sources/KonaneMove.swift +++ b/Sources/KonaneMove.swift @@ -1,14 +1,13 @@ class KonaneMove { - let fromX: Int - let fromY: Int - let toX: Int - let toY: Int - init(fromX: Int, fromY: Int, toX: Int, toY: Int) { - self.fromX = fromX - self.fromY = fromY - self.toX = toX - self.toY = toY + self.fromX = fromX + self.fromY = fromY + self.toX = toX + self.toY = toY } - + + var fromX: Int + var fromY: Int + var toX: Int + var toY: Int } diff --git a/Sources/KonaneMoveInputSource.swift b/Sources/KonaneMoveInputSource.swift index a2554b4..fa0304b 100644 --- a/Sources/KonaneMoveInputSource.swift +++ b/Sources/KonaneMoveInputSource.swift @@ -1,19 +1,31 @@ class KonaneMoveInputSource { - let isBlack: Bool - + var isBlack: Bool init(isBlack: Bool) { self.isBlack = isBlack } - + + + func removeFirstPiece(gameState: KonaneGameState) -> (x: Int, y: Int) { - fatalError("Override me!") + fatalError("Override this function") } - + func removeSecondPiece(gameState: KonaneGameState) -> (x: Int, y: Int) { - fatalError("Override me!") + fatalError("Override this function") } - + func nextMove(gameState: KonaneGameState) -> KonaneMove { - fatalError("Override me!") + fatalError("Override this function") } } +func KonaneMoveInputSourceHuman(isBlack: Bool) -> Bool { + return true +} + + +/*I don't think you need to add what the function returns as ( ex. -> Bool) but I could be wrong*/ +/* I think this is how to call a function with either print(function) or just saying the function with parameters but I'm not entirely sure */ + +/* Bottom left, 0-indexed are the following properties functions, cuz I'm not really sure... */ + + diff --git a/Sources/KonaneMoveInputSourceHuman.swift b/Sources/KonaneMoveInputSourceHuman.swift deleted file mode 100644 index f933529..0000000 --- a/Sources/KonaneMoveInputSourceHuman.swift +++ /dev/null @@ -1,42 +0,0 @@ -class KonaneMoveInputSourceHuman : KonaneMoveInputSource { - override func removeFirstPiece(gameState: KonaneGameState) -> (x: Int, y: Int) { - while true { - print("Input x coord to remove black piece:") - let x = Int(readLine()!)! - print("Input y coord to remove black piece:") - let y = Int(readLine()!)! - - if gameState.isValid(blackRemove: (x, y)) { - return (x, y) - } - } - } - - override func removeSecondPiece(gameState: KonaneGameState) -> (x: Int, y: Int) { - while true { - print("Input x coord to remove white piece:") - let x = Int(readLine()!)! - print("Input y coord to remove white piece:") - let y = Int(readLine()!)! - - if gameState.isValid(whiteRemove: (x, y)) { - return (x, y) - } - } - } - - override func nextMove(gameState: KonaneGameState) -> KonaneMove { - print("Input x coord to move from:") - let fx = Int(readLine()!)! - print("Input y coord to move from:") - let fy = Int(readLine()!)! - - print("Input x coord to move to:") - let tx = Int(readLine()!)! - print("Input y coord to move to:") - let ty = Int(readLine()!)! - - - return KonaneMove(fromX: fx, fromY: fy, toX: tx, toY: ty) - } -} diff --git a/Sources/main.swift b/Sources/main.swift index eddd5e8..a3780d5 100644 --- a/Sources/main.swift +++ b/Sources/main.swift @@ -1,2 +1,8 @@ +import Foundation + let game = KonaneGame(blackIsHuman: true, whiteIsHuman: true) print("Did black win? \(game.play())") +game.isValid(move: KonaneMove) + + +