Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a5c7026
removed Donald's work
Gemma-B Oct 21, 2016
430e87c
I made a couple of changes, mainly just testing it out, btw this is A…
Oct 23, 2016
3b09ea8
I added a couple more properties to the file, I'm commiting it so I d…
Oct 23, 2016
0cd7387
I mite be doing something wrong, care to help out? :)
Oct 24, 2016
f9ea335
wrote skeleton code for KonaneGame as a class and all of it's states
Gemma-B Oct 25, 2016
b1661c6
added skeleton for KonaneGame and created files for other classes
Gemma-B Oct 25, 2016
1fda709
removed a file that held a class that was already written and added s…
Gemma-B Oct 25, 2016
7cf7fb3
I tried to turn some of the list of KonaneGameState into code
Gemma-B Oct 25, 2016
b42b123
copied from Xcode and fixed (?) some of the errors
Gemma-B Oct 27, 2016
37d5684
Random
asthasahoo Oct 27, 2016
e4035e2
jdkjsf
asthasahoo Oct 27, 2016
723e7f2
I tried to fix some errors, but not a lot got done
Gemma-B Oct 27, 2016
e421b0c
Merge branch 'master' of https://github.com/Gemma-B/Final-Project
Gemma-B Oct 27, 2016
ed38d0e
I think most if not all of the errors should be gone
Gemma-B Oct 27, 2016
0241ea2
Hope this works
asthasahoo Oct 28, 2016
a9c8022
Hope this works
asthasahoo Oct 28, 2016
7871944
i just fixed one error because of a curly brace
Gemma-B Oct 28, 2016
047d0ef
i just fixed one error because of a curly brace
Gemma-B Oct 28, 2016
1a27d8a
I'm having trouble with some things,but I fixed and made a couple of …
asthasahoo Oct 29, 2016
da54e44
Fixed and created a couple of errors
asthasahoo Oct 29, 2016
d125876
U guys, I can't fix lines 41-44, help!
asthasahoo Oct 29, 2016
7c4a670
I didn't change anything but I needed to update what code I see, so I…
Gemma-B Oct 31, 2016
f59d3e2
I didn't change anything but I needed to update what code I see, so I…
Gemma-B Oct 31, 2016
7c7dc21
I don't know if I fixed anything, or if I just ended up adding more …
Gemma-B Oct 31, 2016
7478279
I fixed a couple syntax errors but nothing too substantial
Gemma-B Nov 2, 2016
86c9fd7
Need to tdo this
asthasahoo Nov 3, 2016
c19046d
Merge branch 'master' of https://github.com/Gemma-B/Final-Project
asthasahoo Nov 3, 2016
a6492cc
Help on Wednesday meeting, fixed(?) a lot of stuff
Gemma-B Nov 3, 2016
cbb0202
fixed merge errors after Donald's help
Gemma-B Nov 3, 2016
089c80a
I kinda fucked around... not a lot done
Gemma-B Nov 4, 2016
d9cdd48
Put the classes into their own folders and there is a error because d…
Gemma-B Nov 9, 2016
c1749f2
updated stuff, @ a meeting so astha can help
Gemma-B Nov 10, 2016
9c4726a
I tried to fix some errors, but could you ask Donald, like on piazza,…
Gemma-B Nov 10, 2016
31a5335
I fixed like 2 errors, and I'm gonna have dinner and try to see if th…
Gemma-B Nov 15, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Alex wuz here
4 changes: 3 additions & 1 deletion Sources/KonaneColor.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enum KonaneColor {
case black, white, empty
case black
case white
case empty
}
100 changes: 17 additions & 83 deletions Sources/KonaneGame.swift
Original file line number Diff line number Diff line change
@@ -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..<gameState.height).reversed() {
var lineText = "\(y) "
if y < 10 {
lineText.append(" ")
}
for x in (0..<gameState.width) {
let color = gameState.color(atX: x, atY: y)
let colorText: String
if color == KonaneColor.black {
colorText = "x"
} else if color == KonaneColor.white {
colorText = "o"
} else {
colorText = " "
}
lineText.append("\(colorText) ")
}
print(lineText)
}

// Bottom row of coordinates
var bottomRow = " "
for x in 0..<gameState.width {
bottomRow.append("\(x) ")
if x < 10 {
bottomRow.append(" ")
}
}
print()
print(bottomRow)
// an array of columns inside an array of rows, I think. Or vice-versa
}

}
115 changes: 45 additions & 70 deletions Sources/KonaneGameState.swift
Original file line number Diff line number Diff line change
@@ -1,88 +1,63 @@
class KonaneGameState {
let width = 16
let height = 16

private var board: [[KonaneColor]] // Each inner array is a column on the board
private var isBlackTurn = true

init() {
let singleCol = [KonaneColor](repeating: KonaneColor.empty, count: height)

board = [[KonaneColor]](repeating: singleCol, count: width)

// Checkerboard
var width: Int = 16
var height: Int = 16
// the InternalBoardDataStorage wasn't working because I think internal by itself is a command so I changed it to be a name all together
private var isBlackTurn: Bool
init(_ height: Int,_ width: Int,_ isBlackTurn: Bool ) {
self.isBlackTurn = isBlackTurn
self.width = width
self.height = height
InternalBoardDataStorage = [[KonaneColor]](repeating: [KonaneColor](repeating: KonaneColor.empty, count: height), count: width)
for x in 0..<width {
for y in 0..<height {
if (x + y) % 2 == 0 {
board[x][y] = KonaneColor.black
} else {
board[x][y] = KonaneColor.white
if (x + y) % 2 == 0{
InternalBoardDataStorage[x][y] = KonaneColor.black
}
else {
InternalBoardDataStorage[x][y] = KonaneColor.white
}
}
}
self.height = height
self.width = width
}

func copy() -> 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
}

}
19 changes: 9 additions & 10 deletions Sources/KonaneMove.swift
Original file line number Diff line number Diff line change
@@ -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
}
28 changes: 20 additions & 8 deletions Sources/KonaneMoveInputSource.swift
Original file line number Diff line number Diff line change
@@ -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... */


42 changes: 0 additions & 42 deletions Sources/KonaneMoveInputSourceHuman.swift

This file was deleted.

6 changes: 6 additions & 0 deletions Sources/main.swift
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
import Foundation

let game = KonaneGame(blackIsHuman: true, whiteIsHuman: true)
print("Did black win? \(game.play())")
game.isValid(move: KonaneMove)