Difference between revisions of "ECE497 Project BattleShip"

From eLinux.org
Jump to: navigation, search
(Theory of Operation)
Line 58: Line 58:
 
This game can be played either on a computer or the BeagleBone Blue. Internet connection needs to be established before running the game, unless the user wants to play on a single device. The game is started from the terminal. Upon starting the game, the user is prompted to be either 'player 1' or 'player 2'. Player 1 acts as the server and sets up a socket in python. Player 2 needs the IP address of the server (player 1) in order to connect, or 'localhost' if it's being played on a single device. In order to run this code successfully on the beaglebone Blue the device must be connected directly to the network wifi and not masquerading as your local machine. To do this, follow this link: https://github.com/beagleboard/beaglebone-blue/wiki/Frequently-Asked-Questions-(FAQ)#how-do-i-connect-beaglebone-blue-to-my-own-wifi-network and connect to the wifi of your choice. Then have player 1 run the ifconfig to get the proper IP address of the bone. The IP address to grab is next to inet under the wlan0 section once the ifconfig command is ran.   
 
This game can be played either on a computer or the BeagleBone Blue. Internet connection needs to be established before running the game, unless the user wants to play on a single device. The game is started from the terminal. Upon starting the game, the user is prompted to be either 'player 1' or 'player 2'. Player 1 acts as the server and sets up a socket in python. Player 2 needs the IP address of the server (player 1) in order to connect, or 'localhost' if it's being played on a single device. In order to run this code successfully on the beaglebone Blue the device must be connected directly to the network wifi and not masquerading as your local machine. To do this, follow this link: https://github.com/beagleboard/beaglebone-blue/wiki/Frequently-Asked-Questions-(FAQ)#how-do-i-connect-beaglebone-blue-to-my-own-wifi-network and connect to the wifi of your choice. Then have player 1 run the ifconfig to get the proper IP address of the bone. The IP address to grab is next to inet under the wlan0 section once the ifconfig command is ran.   
  
Once the connection is established, both players may place their ships. To place their ships, move the cursor around to where you want to place your ship and then press the action button. To move 
+
Once the connection is established, both players may place their ships. To place their ships, move the cursor around, by using the arrow keys on your computer, to where you want to place your ship and then press the enter key. Then you press the arrow key in whichever direction you would like to place your ship. You do this for all five of your ships, starting with the longest ship and moving down to the lowest ship (5, 4, 3, 3, and then 2 squares in length).  
  
once both players have each other's boards. player 1 gets the first turn. player 1's play board, and the opponent board is updated and the opponent's board is sent over the connection. the opponent(player 2) can then see what player 1's first move is. player 2 continues, and is then allowed to take their turn.  
+
When both players have placed all of their ships, it is then player 1's turn to go first. Player 1 moves the cursor around on a now blank blue board and hits enter where that player would like to shoot. If the shot is a hit, then the square will turn red. If the shot is a miss then the square will turn yellow. After the shot, player 2 will have the screen pop up with a board showing where they placed their ships and where the opponent had shot. Then they hit enter for the screen to go back to their own board of where they are to shoot at. Player 2 moves the cursor around and hits enter where they would like to shoot. This game-play continues until someone has sank all their opponents ships.
  
the game keeps track of the number of hits the player gets. once the hit count(hitCount) reaches 17(number of hits it takes to sink all ships) the winner is notified.
+
In order to win, the game keeps track of the number of hits a player gets. Once the hit count reaches 17(number of hits it takes to sink all ships) the winner is notified. Both players are then asked if they would like to continue through a terminal prompt. 'yes' starts a new game, 'no' quits the game.
 
 
both players are then asked if they would like to continue through a terminal prompt. 'yes' starts a new game, 'no' quits the game.
 
  
 
== Highlights ==
 
== Highlights ==

Revision as of 18:07, 13 November 2017

thumb‎ Embedded Linux Class by Mark A. Yoder


Team members: Dustin D. Kline, Douglas T. Wise, Sara C. Harvey-Browne

Grading Template

0 = Missing, 5=OK, 10=Wow!

00 Executive Summary - not done
00 Installation Instructions - not done
00 User Instructions - dustin
00 Highlights - not done
00 Theory of Operation - Doug
00 Work Breakdown - Sara
00 Future Work - done
00 Conclusions - not done
00 Demo - not done
00 Late
Comments: I'm looking forward to seeing this.

Score:  10/100

(Inline Comment)

Executive Summary

The purpose of this project is to establish a wireless connection between two BeagleBones that will run a game of BattleShip. We will be using pygame to "play" the game and use rotary encoders and push buttons through the BeagleBone ports, or by the use of the enter key and arrow keys from the computer keyboard. The direction inputs will allow the user to move their location on the board to first place ships in the directions of up, down, left, and right, and then move their location to shoot ships of their opponent.


Status of Functioning Portions: Overall game-play of Battleship is fully working. Upon starting the game, the player places their ships. There is logic that does not allow them to overlap ships or wrap the ships around the board. Players take turns taking shots once both players have all five of their ships placed. When it is the players turn, they move the cursor around to where they would like to shoot, then press the 'pause' button on the Beagle to shoot. If the shot is a miss then it will turn the square yellow. If the shot is a hit then it will turn the square red. The player is not allowed to shoot a second time on a red square. At the start of a player's turn they are shown where the opponent shot in reference to where they placed their ships. Once the game is over, the winner is notified and both players are asked if they would like to continue in the terminal on their computer. If both players type in 'yes' then they are put back into the mode where they can place their five ships again. If either player types in 'no' then the program is exited.

Status of Non-Functioning Portions: GPIO button functionality is being worked on.


End with a two sentence conclusion:


Installation Instructions

Here are step by step instructions on how to install your project:

  • Include any additional packages installed via apt.
  • Additional Packages: simplejson, pygame
  • Extra Hardware: push buttons

User Instructions

This game can be played either on a computer or the BeagleBone Blue. Internet connection needs to be established before running the game, unless the user wants to play on a single device. The game is started from the terminal. Upon starting the game, the user is prompted to be either 'player 1' or 'player 2'. Player 1 acts as the server and sets up a socket in python. Player 2 needs the IP address of the server (player 1) in order to connect, or 'localhost' if it's being played on a single device. In order to run this code successfully on the beaglebone Blue the device must be connected directly to the network wifi and not masquerading as your local machine. To do this, follow this link: https://github.com/beagleboard/beaglebone-blue/wiki/Frequently-Asked-Questions-(FAQ)#how-do-i-connect-beaglebone-blue-to-my-own-wifi-network and connect to the wifi of your choice. Then have player 1 run the ifconfig to get the proper IP address of the bone. The IP address to grab is next to inet under the wlan0 section once the ifconfig command is ran.

Once the connection is established, both players may place their ships. To place their ships, move the cursor around, by using the arrow keys on your computer, to where you want to place your ship and then press the enter key. Then you press the arrow key in whichever direction you would like to place your ship. You do this for all five of your ships, starting with the longest ship and moving down to the lowest ship (5, 4, 3, 3, and then 2 squares in length).

When both players have placed all of their ships, it is then player 1's turn to go first. Player 1 moves the cursor around on a now blank blue board and hits enter where that player would like to shoot. If the shot is a hit, then the square will turn red. If the shot is a miss then the square will turn yellow. After the shot, player 2 will have the screen pop up with a board showing where they placed their ships and where the opponent had shot. Then they hit enter for the screen to go back to their own board of where they are to shoot at. Player 2 moves the cursor around and hits enter where they would like to shoot. This game-play continues until someone has sank all their opponents ships.

In order to win, the game keeps track of the number of hits a player gets. Once the hit count reaches 17(number of hits it takes to sink all ships) the winner is notified. Both players are then asked if they would like to continue through a terminal prompt. 'yes' starts a new game, 'no' quits the game.

Highlights

Here is where you brag about what your project can do.

Include a YouTube demo.

Theory of Operation

Battleship is coded in python. At the beginning of the game the user is prompted to be either player 1 or player 2. Player 1 corresponds to the server and player 2 the client. The server sets up a socket in python that the client can connect to. The client needs the IP address of the server and the connection can be made.

There are three boards that the game keeps track of

  • Board: where the user places their ships
  • play_board: the board that displays during gameplay, and shows the users turn actions
  • opponent_board: the user doesn't see this board, it is updated with the play_board and is sent to the opponent to update their Board

The boards are sent back and forth through the socket using simplejson.

The game itself goes through different states of gameplay. First starting with ship placement and then moving on to gameplay.

We use pygame events to keep track of keyboard presses. For loops nested within a while statement, cycle through events and operate the game as controls are input with return also signaling the end of a game state.

While the game is played a hitCount is kept track of, the number of hits needed to win is 17. This check happens after every turn, and if 17 is reached the winner is notified on screen. Before each turn, the game checks to see if the user has lost, by checking the user's board, that has been updated with the opponent's move, for any remaining ship markers(grey tiles). If no grey tiles are left, then that indicates a loss by the user. If they users choose to continue playing, the hitCount and boards are all reset and the game loops back to the beginning, if not it closes.

Work Breakdown

List the major tasks in your project and who did what.

Douglas:

  • Networking the game
  • Client-server code
  • 2 player functionality
  • Screen drawing/updating(player moves)
  • Ship placement
  • Game-play
  • Win checks
  • Post game restart/quit

Dustin:

  • Integrate client-server code into Battleship code
  • Initial Battleship code that worked on one computer
  • Got Battleship code working with pygames on LCD display
  • 2 player functionality
  • Get text to display on screen over the board
  • Win checks
  • Get beaglebone Blue directly connected to school network

Future Work

  • Have Battleship code run right on BeagleBone start-up
  • Create some sort of hardware case for the beaglebone so there is only buttons and LCD display available
  • Keep track of highscore (least amount of shots to win)
  • Get rotary encoders to work as cursor input


Conclusions

Give some concluding thoughts about the project. Suggest some future additions that could make it even more interesting.




thumb‎ Embedded Linux Class by Mark A. Yoder