-
Notifications
You must be signed in to change notification settings - Fork 0
/
board.go
94 lines (77 loc) · 2.02 KB
/
board.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import "fmt"
type board [][]byte
/*
----------------------------------- MAKE BOARD ------------------------------------
The method "makeBoard" creates a new array of the given size filled with dots.
\----------------------------------------------------------------------------------
*/
func makeBoard(size int) board {
res := make([][]byte, size)
for i := range res {
res[i] = make([]byte, size)
for j := range res[i] {
res[i][j] = dot
}
}
return res
}
/*
-------------------------- PRINT ------------------------
The method "print" prints the board.
\--------------------------------------------------------
*/
func (b board) print() {
for i := range b {
fmt.Println(string(b[i]))
}
}
/*
------------------------------------ CHECK ------------------------------------
The method "check" checks if a tetrimino can be placed in a specific
position on the board.
\-------------------------------------------------------------------------------
*/
func (b board) check(i, j int, t tetrimino) bool {
for l := range t {
for x := range t[l] {
if t[l][x] == hashTag {
if i+l >= len(b) || j+x >= len(b) {
return false
}
if b[i+l][j+x] != dot {
return false
}
}
}
}
return true
}
/*
------------------------------------ PUT ------------------------------------
The method "put" places a tetrimino in a specific position on the board.
\----------------------------------------------------------------------------
*/
func (b board) put(i, j, idx int, t tetrimino) {
for y := range t {
for x := range t[y] {
if t[y][x] == hashTag {
b[i+y][j+x] = byte(idx + 'A')
}
}
}
}
/*
-------------------------------------- REMOVE ------------------------------------
The method "remove" removes a tetrimino from a specific position on the board.
\---------------------------------------------------------------------------------
*/
func (b board) remove(i, j int, t tetrimino) {
for y := range t {
for x := range t[y] {
if t[y][x] == hashTag {
b[i+y][j+x] = dot
}
}
}
}