Bladeren bron

Added missing consts to Exercise 4.2

Sanjay Madhav 8 jaren geleden
bovenliggende
commit
4f4a026366
2 gewijzigde bestanden met toevoegingen van 12 en 12 verwijderingen
  1. 6 6
      Exercises/4.2/Board.cpp
  2. 6 6
      Exercises/4.2/Board.h

+ 6 - 6
Exercises/4.2/Board.cpp

@@ -20,7 +20,7 @@ BoardState::BoardState()
 	}
 }
 
-std::vector<BoardState*> BoardState::GetPossibleMoves()
+std::vector<BoardState*> BoardState::GetPossibleMoves() const
 {
 	std::vector<BoardState*> retVal;
 
@@ -41,7 +41,7 @@ std::vector<BoardState*> BoardState::GetPossibleMoves()
 	return retVal;
 }
 
-bool BoardState::IsTerminal()
+bool BoardState::IsTerminal() const
 {
 	// Is the board full?
 	if (IsFull())
@@ -59,7 +59,7 @@ bool BoardState::IsTerminal()
 	return false;
 }
 
-float BoardState::GetScore()
+float BoardState::GetScore() const
 {
 	// If the board is full, the score is 0
 	if (IsFull())
@@ -77,7 +77,7 @@ float BoardState::GetScore()
 	return CalculateHeuristic();
 }
 
-bool BoardState::IsFull()
+bool BoardState::IsFull() const
 {
 	bool isFull = true;
 	for (int i = 0; i < 6; i++)
@@ -94,7 +94,7 @@ bool BoardState::IsFull()
 	return isFull;
 }
 
-int BoardState::GetFourInARow()
+int BoardState::GetFourInARow() const
 {
 	// Returns 1 if yellow wins, -1 if red wins, 0 otherwise
 
@@ -184,7 +184,7 @@ int BoardState::GetFourInARow()
 	return 0;
 }
 
-float BoardState::CalculateHeuristic()
+float BoardState::CalculateHeuristic() const
 {
 	// TODO: You could change this to calculate an actual heuristic
 	return 0.0f;

+ 6 - 6
Exercises/4.2/Board.h

@@ -13,16 +13,16 @@ class BoardState
 {
 public:
 	BoardState();
-	std::vector<BoardState*> GetPossibleMoves();
-	bool IsTerminal();
-	float GetScore();
+	std::vector<BoardState*> GetPossibleMoves() const;
+	bool IsTerminal() const;
+	float GetScore() const;
 
 	enum SquareState { Empty, Red, Yellow };
 	SquareState mBoard[6][7];
 protected:
-	bool IsFull();
-	int GetFourInARow();
-	float CalculateHeuristic();
+	bool IsFull() const;
+	int GetFourInARow() const;
+	float CalculateHeuristic() const;
 };
 
 // Try to place the player's piece