From c1b6ffe70bd281c6c230fd63fabcaac2aff47514 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 7 Apr 2024 23:18:32 -0700 Subject: feat: initial commit --- chapter14/connect4.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 chapter14/connect4.h (limited to 'chapter14/connect4.h') diff --git a/chapter14/connect4.h b/chapter14/connect4.h new file mode 100644 index 0000000..459f2f3 --- /dev/null +++ b/chapter14/connect4.h @@ -0,0 +1,58 @@ +// File: connect4.h (part of the namespace main_savitch_14) +#ifndef MAIN_SAVITCH_CONNECT4 +#define MAIN_SAVITCH_CONNECT4 +#include // Provides queue +#include // Provides string +#include "game.h" // Provides the game base class + +namespace main_savitch_14 +{ + class connect4 : public game + { + public: + // STATIC CONSTANTS + static const int ROWS = 6; + static const int COLUMNS = 7; + + // CONSTRUCTOR + connect4( ); + + protected: + // ******************************************************************* + // VIRTUAL FUNCTIONS (these are overridden from the game base class) + // ******************************************************************* + // Return a pointer to a copy of myself: + virtual game* clone( ) const; + // Compute all the moves that the next player can make: + virtual void compute_moves(std::queue& moves) const; + // Display the status of the current game: + virtual void display_status( ) const; + // Evaluate the current board position. + // NOTE: Positive values are good for the last_mover( ). + virtual int evaluate( ) const; + // Return true if the current game is finished: + virtual bool is_game_over( ) const; + // Return true if the given move is legal for the next player: + virtual bool is_legal(const std::string& move) const; + // Have the next player make a specified move: + virtual void make_move(const std::string& move); + // Restart the game from the beginning: + virtual void restart( ); + + private: + // HELPER FUNCTIONS + int value(int row, int column, int delta_r, int delta_c) const; + + // HELPER CONSTANTS. See connect4.cxx for their values. + static const int COLUMN_DISPLAY_WIDTH; + static const int FOUR_VALUE; + static const std::string MOVE_STRINGS[COLUMNS]; + + // MEMBER VARIABLES TO TRACK THE STATE OF THE GAME + who data[ROWS][COLUMNS]; + int many_used[COLUMNS]; + int most_recent_column; + }; +} + +#endif -- cgit v1.2.3