a geicko-2 based round robin ranking system designed to test c++ battleship submissions battleship.dunkirk.sh
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: remove battleship.h to prevent header conflicts with battleship_light.h

-96
-96
battleship-engine/src/battleship.h
··· 1 - #ifndef BATTLESHIP_H 2 - #define BATTLESHIP_H 3 - 4 - // Author: Keith Shomper 5 - // Date: 24 Oct 03 6 - // Purpose: Header file for implementing a text-based battleship game 7 - // Updated: 14 Nov 08 to align class types with Cedarville standard 8 - // Updated: 3 Apr 14 to use struct rather than class for the defined types 9 - // Updated: 5 Nov 15 to introduce new functions to replace the ISAxxx macros 10 - // and also the SHIPNUM and DEBUGOUT macros 11 - 12 - // include files for implementing battleship 13 - #include <iostream> 14 - #include <cstdlib> 15 - #include <time.h> 16 - #include "kasbs.h" 17 - 18 - using namespace std; 19 - 20 - // use these constants to indicate if the player is a human or a computer 21 - // battleship board size is 10x10 grid (defined in kasbs.h) 22 - 23 - // data structure for position 24 - struct Position { 25 - int startRow; // ship's initial row 26 - int startCol; // ship's initial column 27 - int orient; // indicates whether the ship is running across 28 - // or up and down 29 - }; 30 - 31 - // data structure for ship 32 - struct Ship { 33 - Position pos; // where the ship is on the board 34 - int size; // number of hits required to sink the ship 35 - int hitsToSink; // number of hits remaining before the ship is sunk 36 - char marker; // the ASCII marker used to denote the ship on the 37 - // board 38 - }; 39 - 40 - // a game board is made up of a 10x10 playing grid and the ships 41 - struct Board { 42 - char grid[BOARDSIZE][BOARDSIZE]; 43 - Ship s[6]; // NOTE: the first (zeroth) position is left empty 44 - }; 45 - 46 - // use these constants for designating to which player we are referring 47 - const int HUMAN = 0; 48 - const int COMPUTER = 1; 49 - 50 - // use these constants for deciding whether or not the user gave a proper move 51 - const int VALID_MOVE = 0; 52 - const int ILLEGAL_FORMAT = 1; 53 - const int REUSED_MOVE = 2; 54 - 55 - // functions for screen control and I/O 56 - void welcome(bool debug = false, bool pf = false); 57 - void clearTheLine(int x); 58 - void clearTheScreen(void); 59 - void pauseForEnter(void); 60 - string getResponse(int x, int y, string prompt); 61 - void writeMessage(int x, int y, string message); 62 - void writeResult(int x, int y, int result, int playerType); 63 - void displayBoard(int x, int y, int playerType, const Board &gameBoard); 64 - 65 - // functions to control the board situation 66 - void initializeBoard(Board &gameBoard, bool file = false); 67 - int playMove(int row, int col, Board &gameBoard); 68 - 69 - // function to tell what happened in the last play_move() command 70 - bool isAMiss(int playMoveResult); 71 - bool isAHit (int playMoveResult); 72 - bool isASunk(int playMoveResult); // formerly named isItSunk() 73 - int isShip (int playMoveResult); 74 - 75 - // misc game functions 76 - string randomMove(void); 77 - int checkMove(string move, const Board &gameBoard, int &row, int &col); 78 - void debug(string s, int x = 22, int y = 1); 79 - string numToString(int x); 80 - 81 - #ifdef BATTLESHIP_BACKWARD_COMPATIBILITY 82 - 83 - // former function signatures 84 - void debug(int x, int y, string s); 85 - bool isItSunk(int playMoveResult); 86 - 87 - // a debug macro 88 - #ifdef DEBUG 89 - #define DEBUGOUT(str) debug (22, 1, (str)); 90 - #else 91 - #define DEBUGOUT(str) 92 - #endif // DEBUG 93 - 94 - #endif // BATTLESHIP_BACKWARD_COMPATABILITY 95 - 96 - #endif // BATTLESHIP_H