Last active
December 20, 2019 00:51
-
-
Save mikeatlas/4ef723be8bd3a3dbbebdb9b59e439db4 to your computer and use it in GitHub Desktop.
some kind of board game like reversi/othello but with colors?
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
package main | |
import "fmt" | |
func main() { | |
initialBoard := [][]int{ | |
[]int{1, 1, 1, 4}, | |
[]int{1, 1, 2, 4}, | |
[]int{2, 1, 2, 4}, | |
[]int{1, 1, 2, 4}, | |
} | |
// will print [[3 3 3 4] [3 3 2 4] [2 3 2 4] [1 3 2 4]] | |
fmt.Printf("%v ", nextTurn(3, initialBoard)) | |
} | |
func nextTurn(c int, board [][]int) [][]int { | |
oldc := board[0][0] | |
board[0][0] = c | |
return nextTurnR(c, oldc, 0, 0, board) | |
} | |
func nextTurnR(c, oldc, x, y int, board [][]int) [][]int { | |
if y+1 < len(board[x]) { | |
if board[x][y+1] == oldc { | |
board[x][y+1] = c | |
board = nextTurnR(c, oldc, x, y+1, board) | |
} | |
} | |
if x+1 < len(board) { | |
if board[x+1][y] == oldc { | |
board[x+1][y] = c | |
board = nextTurnR(c, oldc, x+1, y, board) | |
} | |
} | |
return board | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment