diff options
Diffstat (limited to 'backend.go')
-rw-r--r-- | backend.go | 31 |
1 files changed, 22 insertions, 9 deletions
@@ -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 |