From 23cc2b374fd135e45b06e54059c6bc9009f60e31 Mon Sep 17 00:00:00 2001 From: gabe farrell Date: Mon, 21 Feb 2022 00:23:12 -0500 Subject: [PATCH] fixed some silly mistakes and bugs --- board/board.go | 4 ++-- board/clearscreen.go | 2 +- main.go | 7 +++++-- player/player.go | 3 +++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/board/board.go b/board/board.go index 8dc98d4..5067111 100644 --- a/board/board.go +++ b/board/board.go @@ -173,7 +173,7 @@ func (b Board) shipExistsAt(coords []Point) bool { func (b *Board) PlaceShip(s Ship, p Point, vertical bool) (Ship, error) { switch vertical { case true: - if p.Row+rune(s.Length) > 'j' { + if p.Row+rune(s.Length-1) > 'j' { break } for i := 0; i < s.Length; i++ { @@ -189,7 +189,7 @@ func (b *Board) PlaceShip(s Ship, p Point, vertical bool) (Ship, error) { } return s, nil case false: - if p.Col+s.Length > 10 { + if p.Col+s.Length-1 > 10 { break } for i := 0; i < s.Length; i++ { diff --git a/board/clearscreen.go b/board/clearscreen.go index 8471e8b..715a6de 100644 --- a/board/clearscreen.go +++ b/board/clearscreen.go @@ -23,7 +23,7 @@ func PrintLogo() { cprint.Printf["Magenta"]("| $$$$$$ | $$$$$$$$ | $$ | $$$$$$$/\n") cprint.Printf["Magenta"](" \\____ $$| $$__ $$ | $$ | $$____/ \n") cprint.Printf["Magenta"](" /$$ \\ $$| $$ | $$ | $$ | $$ \n") - cprint.Printf["Magenta"](" $$$$$$/| $$ | $$ /$$$$$$| $$ \n") + cprint.Printf["Magenta"]("| $$$$$$/| $$ | $$ /$$$$$$| $$ \n") cprint.Printf["Magenta"](" \\______/ |__/ |__/|______/|__/ \n") cprint.Printf["Red"]("Press ctrl + c at any time to quit.\n\n") } diff --git a/main.go b/main.go index 4211b0e..06df8b3 100644 --- a/main.go +++ b/main.go @@ -30,7 +30,7 @@ import ( "github.com/ghfarrell/go-battleship/player" ) -func PlayerGoesFirst() bool { +func PlayerGoesFirst() (b bool) { var playerGuess int for { cprint.Printf["Cyan"]("Time to determine who goes first! Guess a number 1-6: ") @@ -50,13 +50,16 @@ func PlayerGoesFirst() bool { cprint.Printf["Cyan"]("The AI guessed %d, so the winner is...\n", aiGuess) if math.Abs(float64(r-playerGuess)) < math.Abs(float64(r-aiGuess)) { cprint.Printf["Cyan"]("You! You will make your strike first.\n") + b = true } else if math.Abs(float64(r-playerGuess)) == math.Abs(float64(r-aiGuess)) { cprint.Printf["Cyan"]("You... via tiebreaker!\nYou both guessed %d, but I like you more than the AI.\n", playerGuess) + b = true } else { cprint.Printf["Cyan"]("The AI! Too bad! They will strike first.\n") + b = false } time.Sleep(3 * time.Second) - return true + return } func playerWin() { diff --git a/player/player.go b/player/player.go index f841fb8..9d118d1 100644 --- a/player/player.go +++ b/player/player.go @@ -242,6 +242,9 @@ func (a *AI) getGuess() (c board.Point) { } func (a *AI) Guess(p *Player, debug bool) bool { + board.ClearScreen() + p.PrintEnemy() + p.PrintFriendly() c := a.getGuess() a.Guesses = append(a.Guesses, c) cprint.Printf["White"]("Now the AI's time to strike...\n")