Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
baef675
Donald ya dumbass
Ahill20 Oct 21, 2016
8883914
Undid Donald's demo change to main.swift
isoule Oct 21, 2016
5cedba1
Adding File Directory
Ahill20 Oct 21, 2016
5f5d589
Merge branch 'master' of https://github.com/Ahill20/Final-Project
Ahill20 Oct 21, 2016
2d16823
Create enum for piece type in KonaneColor.swift
isoule Oct 21, 2016
ade1c1c
ASCII Art Gameboard real
Ahill20 Oct 21, 2016
937f27c
Merge branch 'master' of https://github.com/Ahill20/Final-Project
Ahill20 Oct 21, 2016
6b045b7
GameStateCommit
Ahill20 Oct 21, 2016
b76a6a9
Created internal board data structure AND code to print an oriented a…
isoule Oct 22, 2016
dc53cba
I hope this works Alex's code
Ahill20 Oct 22, 2016
1c12363
Ionaton I hope this works
Ahill20 Oct 22, 2016
484075a
I fucked up the enum -Alex
Ahill20 Oct 22, 2016
5143246
Addition of PieceRemovalSearch Function
Ahill20 Oct 22, 2016
fa8579d
Clearer functions
Ahill20 Oct 22, 2016
8bf2fd2
Fixed func printGameBoard() in KonaneGameState.swift - it excluded th…
isoule Oct 22, 2016
d22f7aa
Made KonaneGameState a class along with some other minor changes
isoule Oct 22, 2016
3887d3c
Added func color() -> KonaneColor {...}
isoule Oct 22, 2016
e270b6b
Finished up code to initialize KonaneGame.swift with user input
isoule Oct 22, 2016
f809a53
Clearified some comments and wrote code for func color(...) -> Konane…
isoule Oct 22, 2016
b12d779
Some changes
isoule Oct 23, 2016
6b23170
FINISHED KonaneMove.swift
isoule Oct 23, 2016
c7efe3d
Don't think I actually changed anything lol
isoule Oct 23, 2016
0f4ab5d
Fixex all of KonaneGameState.swift and corrected classes and function…
Ahill20 Oct 24, 2016
f62faa7
A lot of changes to reformat everything
Ahill20 Oct 26, 2016
5da870e
Corrected KonaneGame's class and printed successfully
Ahill20 Oct 26, 2016
1bdbe40
Blank sheet code
Ahill20 Oct 27, 2016
7586e38
Reformat all te things
Ahill20 Oct 27, 2016
91a60f5
More changes
Ahill20 Oct 27, 2016
e33ce15
Donald's a wizard
isoule Oct 27, 2016
f6f4ed6
In class changes
Ahill20 Oct 27, 2016
63be339
Completed skeleton functions for KonaneMoveInputSource
millerja14 Oct 27, 2016
c395eac
Named all necessary func in KonaneGameState.swift
isoule Oct 27, 2016
f23d095
Completed skeleton functions for KonaneMoveInputSource
millerja14 Oct 27, 2016
59c03b1
Fixed merge conflict
isoule Oct 27, 2016
9dc15b5
Merge branch 'master' of https://github.com/Ahill20/Final-Project
isoule Oct 27, 2016
9a2f755
Merge conflict
Ahill20 Oct 27, 2016
7601062
Merge branch 'master' of https://github.com/Ahill20/Final-Project
Ahill20 Oct 27, 2016
a6e59d0
Fix variables in KonaneGame.swift and add play() function
Ahill20 Oct 27, 2016
edc4d5e
Not sure what I did
isoule Oct 27, 2016
ea14115
Editted functions in KonaneMoveInputSource
millerja14 Oct 27, 2016
cb20494
Merge branch 'master' of https://github.com/Ahill19/Final-Project
millerja14 Oct 27, 2016
cd4312f
Fixing KonaneMove to delete unecessary functions
Ahill20 Oct 27, 2016
c835818
Wrote func color(...)for KonaneGameState.swift
isoule Oct 27, 2016
4e39f29
KonaneMoveInputSourceHuman dummy
millerja14 Oct 27, 2016
111d78d
Merge branch 'master' of https://github.com/Ahill20/Final-Project
millerja14 Oct 27, 2016
5001317
Moved Functions.swift outside of the Sources directory
Ahill20 Oct 27, 2016
d01371f
Moved Functions.swift outside of the Sources directory
Ahill20 Oct 27, 2016
ddd4d6e
Buggy merge fix
Ahill20 Oct 27, 2016
086f7bf
removeFirstPiece... code-ish
isoule Oct 27, 2016
1b83864
began isValid function
Ahill20 Oct 28, 2016
00f69f2
Added comments on isValid()
Oct 28, 2016
91dd438
Call game.play() outside of print so that it actually works
Oct 30, 2016
924c5b6
Clarified that all of KonaneMoveInputSource's methods are defined in …
Oct 30, 2016
52c4508
minimax
Oct 30, 2016
6eb20bc
Improved clarity of text prompt
Oct 30, 2016
7f9f7fa
Made play return a bool
Nov 2, 2016
f70ded8
Added play() method
Nov 2, 2016
169edec
Fixed /n error
Nov 2, 2016
6f3e373
Fixed readline -> readLine
Nov 2, 2016
2626aa5
Fixed curly braces
Nov 2, 2016
04119c6
Fixed readLine()s
Nov 2, 2016
3ecb29c
Tried to make buildable
Nov 2, 2016
5b9a4d2
Fixed spelling
Nov 2, 2016
41e2d3d
Finalized is valid function?
Ahill20 Nov 3, 2016
b8c2be0
Merge branch 'master' of https://github.com/Ahill20/Final-Project
Ahill20 Nov 3, 2016
4d60802
Merge error fix
Ahill20 Nov 3, 2016
d23f31c
Wrote is valid functions in GameState
Ahill20 Nov 3, 2016
57454a3
Merge branch 'master' of https://github.com/Ahill20/Final-Project
Ahill20 Nov 3, 2016
e0f1333
Merge branch 'master' of https://github.com/Ahill20/Final-Project
Nov 2, 2016
c4b67c0
Modify isValid for white
Nov 3, 2016
3d9baa6
Fixed x and y values for isValid functions
Ahill20 Nov 4, 2016
3faea4f
WORKING FUCKING SWIFT BUILD MOTHER FUCKERS
Ahill20 Nov 4, 2016
317bf6e
wrote perform remove funcitons
Ahill20 Nov 4, 2016
a80dc7d
Dick me silly
Ahill20 Nov 4, 2016
31ff9b4
Merge branch 'master' of https://github.com/Ahill20/Final-Project
Ahill20 Nov 4, 2016
087bd82
Fixing build errors involving perform()
Nov 3, 2016
45a7df4
No private on isBlackTurn
Ahill20 Nov 4, 2016
cec6d81
Wrote game.play?????? maybe....?
Ahill20 Nov 4, 2016
90ed93d
Actually populating the gameboard
Ahill20 Nov 4, 2016
1d3d1c6
Made it actually work...kinda
Nov 3, 2016
a035d73
fixed is valid remove funtion
Ahill20 Nov 4, 2016
6f5615f
Readded Functions.swift
Nov 3, 2016
204eaa8
So I guess jumping a piece FUCKING WORKS NOW
Ahill20 Nov 7, 2016
22c3ed1
Finalized move and didWin functions
Ahill20 Nov 7, 2016
0aa16de
Everything workinggit add -A!
Ahill20 Nov 8, 2016
e33b18f
Working isValid whiteRemove function for sides of gameboard
Ahill20 Nov 9, 2016
727e259
Idk a few changes to didWin
Ahill20 Nov 10, 2016
4a7593c
continuosly asks for input
Ahill20 Nov 10, 2016
7b5b3ee
Begin AI, look for moves
isoule Nov 10, 2016
40727b0
Merge branch 'master' of https://github.com/Ahill20/Final-Project
isoule Nov 10, 2016
941f4e8
Can't touch this bu du du du du du, can't touch this (code) Made it …
Ahill20 Nov 10, 2016
0b6908c
Everything working for human to human
Ahill20 Nov 12, 2016
20fc2ff
Merge branch 'master' of https://github.com/Ahill20/Final-Project
Ahill20 Nov 12, 2016
2731758
Changed everything to correct classes and format. Error in didWin fun…
Ahill20 Nov 15, 2016
e678809
Still not working didWin functions
Ahill20 Nov 15, 2016
5fb6f41
did'Color'Win() still not working. It cannot detect when someone has …
isoule Nov 16, 2016
1af7507
Working on AI
isoule Nov 17, 2016
39b15f9
Continued AI dev. Needed to create func copy() in KonaneGameState
isoule Nov 17, 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
Binary file added .DS_Store
Binary file not shown.
Binary file added Sources/.DS_Store
Binary file not shown.
14 changes: 12 additions & 2 deletions Sources/KonaneColor.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
//
// KonaneColor.swift
//
//
// Created by Alex Hill on 10/20/16.
//
//

import Foundation

enum KonaneColor {
case black, white, empty
}
case black, white, empty
}
197 changes: 129 additions & 68 deletions Sources/KonaneGame.swift
Original file line number Diff line number Diff line change
@@ -1,96 +1,157 @@
//
// KonaneGame.swift
//
//
// Created by Alex Hill on 10/20/16.
//
//

import Foundation

/*
KonaneGame
x - init(blackIsHuman: Bool, whiteIsHuman: Bool)
x - private gameState: KonaneGameState
x - private blackInputSource: KonaneMoveInputSource
x - private whiteInputSource: KonaneMoveInputSource
- play() -> Bool // Returns true if black wins.
- private displayBoard()
*/





//WILL FIX LATER FIRST GETTING INITIALIZATION DONE
class KonaneGame {
private let gameState: KonaneGameState = KonaneGameState()

private var gameState = KonaneGameState(width: 6, height: 6, isBlackTurn: true) //May have broken it
private let blackInputSource: KonaneMoveInputSource
private let whiteInputSource: KonaneMoveInputSource


init(blackIsHuman: Bool, whiteIsHuman: Bool) {

if blackIsHuman {
blackInputSource = KonaneMoveInputSourceHuman(isBlack: true)
} else {
fatalError("Doesn't work yet!")
}

else {
//FIX ONCE AI CODE EXISTS
blackInputSource = KonaneMoveInputSourceAI(isBlack: true)
}
if whiteIsHuman {
whiteInputSource = KonaneMoveInputSourceHuman(isBlack: false)
} else {
fatalError("Doesn't work yet!")
}
else {
//FIX ONCE AI CODE EXISTS
whiteInputSource = KonaneMoveInputSourceAI(isBlack: false)
}
}

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)
func displayBoard() {
var arbitraryVariable = 0

// 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())
for rowNumber in (0..<gameState.height).reversed() {
//Print row numbering
if rowNumber < 10 {
print(" \(rowNumber)", terminator:" ")
}

gameState.perform(move: move)
else {
print("\(rowNumber)", terminator:" ")
}
//Print actual board
for columnNumber in 0..<gameState.width {
if gameState.gameBoard[columnNumber][rowNumber] == KonaneColor.black {
print(" x", terminator: " ") //black square
}
else if gameState.gameBoard[columnNumber][rowNumber] == KonaneColor.white {
print(" o", terminator: " ") //white square
}
else {
print(" ", terminator: " ") //empty square
}
}
print() //uses a terminator to make new line
//Print column numbering
}

let blackWins = gameState.didBlackWin()
if blackWins {
print("Black wins!")
} else {
print("White wins!")
print(" ", terminator:"")
while arbitraryVariable < gameState.height {
if arbitraryVariable < 10 {
print(" \(arbitraryVariable)", terminator: " ")
} else {
print("\(arbitraryVariable)", terminator: " ")
}
arbitraryVariable += 1
}
return blackWins
print()
}

private func displayBoard() {
displayASCIIBoard()


func askForInput() -> (xCoord: Int, yCoord: Int) {
while true {
let x = Int(readLine()!)
let y = Int(readLine()!)
if x != nil && y != nil && x! < gameState.height && y! < gameState.height && x! >= 0 && y! >= 0 {
return (xCoord: x!, yCoord: y!)
} else {
print("This is not a valid input. Try again")
}
}
}


func play() -> Bool {

private func displayASCIIBoard() {
for y in (0..<gameState.height).reversed() {
var lineText = "\(y) "
if y < 10 {
lineText.append(" ")
var winBool = false
var move: KonaneMove = KonaneMove(fromX: 0, fromY: 0, toX: 0, toY: 0)

//real play function
gameState.populateGameBoard()

displayBoard()

gameState.perform(blackRemove: blackInputSource.removeFirstPiece(gameState: gameState))

displayBoard()

gameState.perform(whiteRemove: whiteInputSource.removeSecondPiece(gameState: gameState))

displayBoard()

while winBool == false {
if gameState.getIsBlackTurn() {
move = blackInputSource.nextMove(gameState: gameState)
} else if !gameState.getIsBlackTurn() {
move = whiteInputSource.nextMove(gameState: gameState)
} else {
print("Error not black or white's turn?")
}
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) ")

gameState.perform(move: move)

if gameState.getIsBlackTurn() && gameState.didBlackWin() {
winBool = true
} else if !gameState.getIsBlackTurn() && gameState.didWhiteWin() {
winBool = true
} else {
winBool = false
}
print(lineText)

//Changes turn
gameState.isBlackTurn = !gameState.isBlackTurn

displayBoard()
}

// Bottom row of coordinates
var bottomRow = " "
for x in 0..<gameState.width {
bottomRow.append("\(x) ")
if x < 10 {
bottomRow.append(" ")
}
//Need to account for the fact that the player has changed
//That's why the code and players seem switched
if !gameState.getIsBlackTurn() {
print("Player1 (x's) has won the game!")
} else if gameState.getIsBlackTurn() {
print("Player2 (o's) has won the game!")
}
print()
print(bottomRow)
return winBool
}
}
//End of Class
Loading