+class Solution:
+ """
+ A representation of the solution of a linear game. It should contain
+ the value of the game, and both players' strategies.
+ """
+ def __init__(self, p1_value, p2_value, p1_optimal, p2_optimal):
+ self._player1_value = p1_value
+ self._player2_value = p2_value
+ self._player1_optimal = p1_optimal
+ self._player2_optimal = p2_optimal
+
+ def __str__(self):
+ """
+ Return a string describing the solution of a linear game.
+
+ The three data that are described are,
+
+ * The value of the game.
+ * The optimal strategy of player one.
+ * The optimal strategy of player two.
+
+ """
+ # The string representations of the player strategy matrices
+ # already contain trailing newlines.
+ tpl = 'Game value: {:.7f}\n' \
+ 'Player 1 optimal: {!s}' \
+ 'Player 2 optimal: {!s}'
+ return tpl.format(self.game_value(),
+ self.player1_optimal().trans(),
+ self.player2_optimal().trans())
+
+ def game_value(self):
+ return ((self.player1_value() + self.player2_value()) / 2.0)
+
+ def player1_value(self):
+ return self._player1_value
+
+ def player2_value(self):
+ return self._player2_value
+
+ def player1_optimal(self):
+ return self._player1_optimal
+
+ def player2_optimal(self):
+ return self._player2_optimal
+
+