-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
188 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
mawu[] board = ["","","","","","","","",""]; | ||
mawu currentPlayer = "X"; | ||
nambala isRunning = zoona; | ||
|
||
ndondomeko printBoard() { | ||
lembanzr("---------"); | ||
lembanzr(board[0] + " | " + board[1] + " | " + board[2]); | ||
lembanzr("---------"); | ||
lembanzr(board[3] + " | " + board[4] + " | " + board[5]); | ||
lembanzr("---------"); | ||
lembanzr(board[6] + " | " + board[7] + " | " + board[8]); | ||
lembanzr("---------"); | ||
} | ||
|
||
ndondomeko checkWin() { | ||
mawu[] winConditions = [ | ||
[0, 1, 2], [3, 4, 5], [6, 7, 8], | ||
[0, 3, 6], [1, 4, 7], [2, 5, 8], | ||
[0, 4, 8], [2, 4, 6] | ||
]; | ||
|
||
za (x = 0; x < winConditions.length(); x++) { | ||
mawu condition = winConditions[x]; | ||
ngati (board[condition[0]] != "" && board[condition[0]] == board[condition[1]] && board[condition[0]] == board[condition[2]]) { | ||
bweza zoona; | ||
} | ||
} | ||
bweza bodza; | ||
} | ||
|
||
ndondomeko move(player, position) { | ||
ngati (board[position] != "") { | ||
bweza bodza; | ||
} | ||
|
||
board[position] = player; | ||
ngati (player == "X") { | ||
currentPlayer = "O"; | ||
} kapena { | ||
currentPlayer = "X"; | ||
} | ||
bweza zoona; | ||
} | ||
|
||
ndondomeko playGame() { | ||
pamene(isRunning) { | ||
printBoard(); | ||
lembanzr("Player " + currentPlayer + " turn: "); | ||
nambala playerMove = kuNambala(console.landira()); | ||
mawu moved = move(currentPlayer, playerMove - 1); | ||
ngati(moved == bodza) { | ||
lembanzr("Invalid move"); | ||
lembanzr("Try again"); | ||
lembanzr("---------"); | ||
// TODO: Implement a way to continue loop | ||
} kapena { | ||
mawu hasWon = checkWin(); | ||
ngati (hasWon == zoona) { | ||
lembanzr("Player " + player + " has won!"); | ||
lembanzr("Game Over"); | ||
isRunning = bodza; | ||
} kapena { | ||
console.fufuta(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
playGame(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package evaluator | ||
|
||
import "github.com/sevenreup/chewa/src/object" | ||
import ( | ||
"github.com/sevenreup/chewa/src/object" | ||
"github.com/sevenreup/chewa/src/values" | ||
) | ||
|
||
func nativeBoolToBooleanObject(input bool) *object.Boolean { | ||
if input { | ||
return TRUE | ||
return values.TRUE | ||
} | ||
return FALSE | ||
return values.FALSE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package functions | ||
|
||
import ( | ||
"github.com/sevenreup/chewa/src/object" | ||
"github.com/sevenreup/chewa/src/token" | ||
"github.com/shopspring/decimal" | ||
) | ||
|
||
func ParseStringToNumber(env *object.Environment, tok token.Token, args ...object.Object) object.Object { | ||
if len(args) != 1 { | ||
// TODO: Return error dont panic | ||
panic("parse requires exactly one argument") | ||
} | ||
|
||
if args[0].Type() != object.STRING_OBJ { | ||
return nil | ||
} | ||
|
||
str := args[0].(*object.String).Value | ||
number, _ := decimal.NewFromString(str) | ||
|
||
return &object.Integer{Value: number} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package values | ||
|
||
import "github.com/sevenreup/chewa/src/object" | ||
|
||
var ( | ||
NULL = &object.Null{} | ||
TRUE = &object.Boolean{Value: true} | ||
FALSE = &object.Boolean{Value: false} | ||
) |