Page 870 - AP Computer Science A, 7th edition
P. 870

21. (C) Remember, to implement the Player interface a class must provide implementations for getMove and updateDisplay. The updateDisplay method is suitable for all five games described. The getMove method returns a single integer, which works well for the High-Low game of choice A and the Chips game of choice B. In Tic-Tac-Toe (choice D) and Battleships (choice E) a move consists of giving a grid location. This can be provided by a single integer if the grid locations are numbered in a unique way. It’s not ideal, but certainly doable. In the Chess game, however, it’s neither easy nor intuitive to describe a move with a single integer. The player needs to specify both the grid location he is moving the piece to and which piece he is moving. The getMove method would need to be altered in a way that changes its return type. This makes the Player interface unsuitable.


































































































   868   869   870   871   872