summaryrefslogtreecommitdiff
path: root/chapter14/connect4.h
blob: 459f2f36e0fe87e1945ef12a583499168f6284d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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