Skip to content

Commit

Permalink
board set up
Browse files Browse the repository at this point in the history
  • Loading branch information
bertoort committed Nov 5, 2015
0 parents commit e25a9c1
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
64 changes: 64 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package main

import (
"fmt"
)

// Sudoku methods
// type Sudoku interface {
// createPuzzle()
// getPuzzle() [9][9]square
// }

// Puzzle class
type Puzzle struct {
board [9][9]square
}

type square struct {
val int
x int
y int
box int
}

func main() {
newBoard := Puzzle{}
fmt.Println(newBoard.createPuzzle())
}

func (p Puzzle) createPuzzle() [9][9]square {
var puzzle [9][9]square
for i, row := range puzzle {
for j := range row {
puzzle[i][j].x = j
puzzle[i][j].y = i
if puzzle[i][j].x < 3 {
if puzzle[i][j].y < 3 {
puzzle[i][j].box = 0
} else if puzzle[i][j].y > 5 {
puzzle[i][j].box = 6
} else {
puzzle[i][j].box = 3
}
} else if puzzle[i][j].x > 5 {
if puzzle[i][j].y < 3 {
puzzle[i][j].box = 2
} else if puzzle[i][j].y > 5 {
puzzle[i][j].box = 8
} else {
puzzle[i][j].box = 5
}
} else {
if puzzle[i][j].y < 3 {
puzzle[i][j].box = 1
} else if puzzle[i][j].y > 5 {
puzzle[i][j].box = 7
} else {
puzzle[i][j].box = 4
}
}
}
}
return puzzle
}
44 changes: 44 additions & 0 deletions puzzle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package puzzle

type square struct {
val int
x int
y int
box int
}

func puzzle() [9][9]square {
var puzzle [9][9]square
for i, row := range puzzle {
for j := range row {
puzzle[i][j].x = j
puzzle[i][j].y = i
if puzzle[i][j].x < 3 {
if puzzle[i][j].y < 3 {
puzzle[i][j].box = 0
} else if puzzle[i][j].y > 5 {
puzzle[i][j].box = 6
} else {
puzzle[i][j].box = 3
}
} else if puzzle[i][j].x > 5 {
if puzzle[i][j].y < 3 {
puzzle[i][j].box = 2
} else if puzzle[i][j].y > 5 {
puzzle[i][j].box = 8
} else {
puzzle[i][j].box = 5
}
} else {
if puzzle[i][j].y < 3 {
puzzle[i][j].box = 1
} else if puzzle[i][j].y > 5 {
puzzle[i][j].box = 7
} else {
puzzle[i][j].box = 4
}
}
}
}
return puzzle
}

0 comments on commit e25a9c1

Please sign in to comment.