summaryrefslogtreecommitdiff
path: root/backend.go
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2020-01-10 23:35:28 -0500
committerBenjamin Chausse <benjamin@chausse.xyz>2020-01-10 23:35:28 -0500
commit2dce3d01308fda5104d26792ee3e305a5f2cbd96 (patch)
treeaa405b1bae85ff892390aeb9c2b8c6d729e3209d /backend.go
parent2a12730d95ef38d3c8b8c441f46d4ae296ebada7 (diff)
Target UI +++ Target backend WORKS
Diffstat (limited to 'backend.go')
-rw-r--r--backend.go31
1 files changed, 22 insertions, 9 deletions
diff --git a/backend.go b/backend.go
index cb258b6..868739d 100644
--- a/backend.go
+++ b/backend.go
@@ -5,9 +5,9 @@ import (
)
type parameters struct {
- vs_cpu bool
- ssh_game bool
- debug bool
+ vsCPU bool
+ sshGame bool
+ debug bool
}
type userError struct {
@@ -90,13 +90,25 @@ type player struct {
prey *player
}
+func (plyr *player) InitBoard(opponent *player) {
+ plyr.prey = opponent
+
+ for i := 0; i < 10; i++ {
+ for j := 0; j < 10; j++ {
+ plyr.primary[i][j] = [3]int{6, 0, 0}
+ plyr.target[i][j] = [2]int{0, 6}
+
+ }
+ }
+}
+
// initBoat places a boat on a players primary grid.
// boat sizes are defined by the boatlist variable.
// Consult it for more info.
-func (plyr *player) initBoat(boatID, orientation, x, y int) {
- boat_length := len(boatlist[boatID][0])
+func (plyr *player) InitBoat(boatID, orientation, x, y int) {
+ boatLength := len(boatlist[boatID][0])
if orientation == 0 { // Boat is HORIZONTAL
- for i := 0; i < boat_length; i++ {
+ for i := 0; i < boatLength; i++ {
char := boatlist[boatID][0][i]
if char == 0 { // Compensating for boatlist having
break // zeros at the end of slices
@@ -107,7 +119,7 @@ func (plyr *player) initBoat(boatID, orientation, x, y int) {
x++ // HORIZONTAL: Therefore the loop increments the x axis
}
} else { // Boat is VERTICAL
- for i := 0; i < boat_length; i++ {
+ for i := 0; i < boatLength; i++ {
char := boatlist[boatID][1][i]
if char == 0 {
break
@@ -121,9 +133,10 @@ func (plyr *player) initBoat(boatID, orientation, x, y int) {
func (plyr *player) Hit(x, y int) bool {
plyr.prey.primary[y][x][2] = 1
+ // We change the coord status to hit and add the id of
+ // the boat since we know it now.
plyr.target[y][x] = [2]int{1, plyr.prey.primary[y][x][0]}
-
- if BoatID := plyr.prey.primary[y][x][0]; BoatID > 0 {
+ if BoatID := plyr.prey.primary[y][x][0]; BoatID < 6 {
switch plyr.prey.primary[y][x][1] {
case 1, 2, 5: // If the hit boat was vertical
// We suppose the boat is sunk since it only takes one unhit coordinate to prove this wrong