summaryrefslogtreecommitdiff
path: root/chapter14/connect4.h
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-04-07 23:18:32 -0700
committerFuwn <[email protected]>2024-04-07 23:18:32 -0700
commitc1b6ffe70bd281c6c230fd63fabcaac2aff47514 (patch)
treee8af3b1782a7cd0754590ed618fddc1bdb9b7385 /chapter14/connect4.h
downloaddscode-main.tar.xz
dscode-main.zip
feat: initial commitHEADmain
Diffstat (limited to 'chapter14/connect4.h')
-rw-r--r--chapter14/connect4.h58
1 files changed, 58 insertions, 0 deletions
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 <queue> // Provides queue<string>
+#include <string> // 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<std::string>& 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