Giter Club home page Giter Club logo

battleship's Introduction

Battleship

Object oriented programming project

Guillaume Claudel, Thibaut Gourdel, Rémi Perrot

ENSEIRB-MATMECA, 2015

T2-G1, Groupe 10

Step 1 : Grid

Importing grid & ships

  • We use the Javax XML Parsers library for importing grid.xml, in the package tools
  • The XmlParser- classes are called in files Grid.java, for parsing both general grid informations and ships positions (ships.xml)

Exceptions / placing AI boats

  • Exceptions are dealt with in the exceptions package
  • Most of the time, they are not catch, but directly sent to the main method
  • However, they are a few exceptions which are catched
    • ShipOutOfBoundsException is catched to determined if the randomly created boat (for the AI) is inside the grid
    • ShipOverlapException is replaced, for random generation, by a simple boolean-return function for testing overlapping between AI boats

Tests

  • Tests for verifying if some of the exceptions are well managed are made in TestException.java, in the test folder, with JUnit 4

Drawing

  • When entering the following command, a svg-debug file is created :
$ java fr.enseirb.battleship.App debug grid.xml ships.xml

Remark : The game has been built in order to be launched on Eclipse. If you want to try it on a terminal, please place yourself in the root directory of the project, and use the option -classpath bin/ in the launch command.

  • The drawing writing process is managed in the SvgWriter class

Step 2 : Game

The game can be launched with the following command :

$ java fr.enseirb.battleship.App play grid.xml ships.xml

The list of the commands is displayed when an error occures.

Turn by turn

  • Function turnOfPlayer(i) processes the turn of IA or Human player
    • It calls the abstract method play of player and his children
  • Keyboards inputs are handled in the play method of Human class, extending Player
  • Random fires of the IA are managed in the play method of IA, extending Player
    • Random coordinates are generated from getRandomCoordinates of Grid
    • They keep being generated while none have been encounter satisfying every conditions of checkHit (Grid)

Updated drawing

  • A debug drawing can still be made by using the same name command during Play mode. See debug.svg
  • view, on the contrary, only shows the full grid of the current player, and the missed/touched fires he made against his opponent. See game.svg

Step 3 : Advanced IA

Strategies

  • Boats placement and firing strategies are indicated in grid.xml by the user.

    • These informations change the way the functions play and randomShips behave.
  • For both placement and firing, the RANDOM strategy is the simplest way the IA plays. Boats and firing coordinates are random.

  • Placement strategies

    • PACK : The pack strategy consists in dividing the grid by rectangular sections. The algorithm chooses one section randomly and places boats in it.
    • FAR : As above, the grid is shared in rectangular sections. However, each section includes only and maximally one boat.
    • PERSO : This strategy is a mix of pack and far strategies. Boats are packed in groups of three and seperated in differents sections
  • Firing strategies

    • PACK : The IA fires coordinates close from each other.
    • FAR : Contrary to the pack strategy, the IA fires coordinates far from each other.
    • PERSO : This is a hybrid strategy. The IA starts by applying the far strategy, and once it touches a boat, it turns to pack strategy in order to sunk the boat.

Bonus : Network

Multiplayer

One user has to launch the game as a server :

$ java fr.enseirb.battleship.App server grid.xml ships.xml [port]

And the other will play as client :

$ java fr.enseirb.battleship.App client grid.xml ships.xml [server IP] [port]
  • RemoteHuman, extending Player, is seamlessly changing the way IA behaved
    • It uses the same function, play, but the program waits for external data
  • An optional opponent socket is added in Human
    • When defined, the class sends through the socket information of human moves
  • At initialization, grids are exchanged between players
    • The use of Java.io.Serializable allows us to convert a Grid to a String
    • Human and RemoteHuman implements respectively sendGridToOpponent and recvGrid for exchanging grids

battleship's People

Contributors

gclaudel avatar remi-p avatar tgourdel avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.