Question: Task 2 Define a class called RandomPlayer that can be used for an unintelligent computer player that chooses at random from the available columns. This

Task 2
Define a class called RandomPlayer that can be used for an unintelligent computer player that chooses at random from the available columns.
This class should be a subclass of the Player class that you implemented in Problem 2, and you should take full advantage of inheritance. In particular, you should not need to include any attributes in your RandomPlayer class, because all of the necessary attributes (the players checker, and its count of the number of moves) will be inherited from Player.
Similarly, you should not need to redefine the __repr__ or opponent_checker methods, because they will be inherited from Player, and we dont want these methods to behave any differently for a RandomPlayer than they do for a Player.
However, you will need to do the following:
Make sure that your class header specifies that RandomPlayer inherits from Player.
Because all of the attributes of a RandomPlayer are inherited from Player, you will not need to define a constructor for this class. Rather, we can just use the constructor that is inherited from Player.
Write a method next_move(self, b) that overrides (i.e., replaces) the next_move method that is inherited from Player. Rather than asking the user for the next move, this version of next_move should choose at random from the columns in the board b that are not yet full, and return the index of that randomly selected column. You may assume that this method will only be called in cases in which there is at least one available column.
In addition, make sure that you increment the number of moves that the RandomPlayer object has made.
Notes:
To ensure that the method does not select the index of a column that is already full, we recommend that you begin by constructing a list containing the indices of all available columns i.e., all columns to which you can still add a checker. For example, lets say that the parameter board represents the following board:
|O|||X||||
|X|||O||||
|X|||O||O||
|X|X||O|X|X|O|
|O|X|O|X|X|O|X|
|O|O|X|O|O|O|X|
---------------
0123456
The list of available columns in this case would be [1,2,4,5,6].
To build this list, you should consider the columns one at a time, and add the index of any available column to the list. This can be done using a loop, or you might want to use a list co

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!