Skip to content

Instantly share code, notes, and snippets.

@mikeatlas
Last active December 20, 2019 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeatlas/4ef723be8bd3a3dbbebdb9b59e439db4 to your computer and use it in GitHub Desktop.
Save mikeatlas/4ef723be8bd3a3dbbebdb9b59e439db4 to your computer and use it in GitHub Desktop.
some kind of board game like reversi/othello but with colors?
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