Skip to content

malandrii/sea-battle-game-winforms

Repository files navigation

"Sea Battle" on Windows Forms

Classic "Sea Battle" game on Windows Forms with Enemy bot.

Installation

Go to Releases, choose the latest release and click the "sea-battle.exe" or just click here.

Usage

1. Place your ships

Place ships panel => choose ship size => mouse cursor on the field

image

mouse left button to place a ship

image

Ships horizontality can be changed

image
image

Ships can be arranged randomly

image

2. Start Game

After you've placed all the ships, choose the enemy settings and press "Start Game".

image

3. Your turns

  • Press on the enemy field button. You and the enemy go one by one.
  • The text of the button displays the turn outcome. dot is a hit, cross is a miss.

image

Status also helps you monitoring current move action.

image

  • When you hit an enemy ship you will be able to continue your moves until you miss.
  • When the enemy ship becomes dead - all the cells around it get covered in dots.

image

image

4. Enemy turns

Meanwhile, enemy-bot is attacking our field!

image

5. End of the Game

  • Game stops the moment someone destroys all of the opponent ships.
  • When it happens you will be able to see where the enemy ships were located.

image

Enemy computer attack algorithm

  1. image -> image

  2. After finding the first piece next move is going to be random around the current piece (1 to 4 in this case) until it hits next time.
    image

    image

  3. When it gets to the edge it checks if the edge's Y-axis coordinate is the same the original "hit" piece to determine whether the ship is horizontal.

    image

  4. Now it goes back to the original ship piece shot and moves the opposite direction (up/down or left/right depending on the condition if the ship is horizontal, which it determined last step).

    image

* Enemy algorithm works the same with any ship size and it also understands if the cell was already shot and attacks the opposite way.
* This algorithm is the most effective way to play "Sea Battle" and usually people use the same strategy.