【发布时间】:2016-10-05 18:23:47
【问题描述】:
不能改变的东西:
enum CellLocation{TOP_LEFT,TOP_CENTER,TOP_RIGHT,CENTRE_LEFT, .. and so on}
enum CellState{OCCUPIED_BY_X,OCCUPIED_BY_O,EMPTY}
一个游戏板界面,只包含一个方法:
CellState getCellState(CellLocation cellLocation);
一个顾问接口,其中也包含一个方法:
CellLocation suggest(GameBoard gameBoard);
我的工作是创建一个实现顾问接口的类并覆盖给定的建议方法(该方法还必须决定下一个播放器 -> Cellocation 输出必须具有 EMPTY 状态)
所以,我的问题是我不知道如何开始。我正在考虑在建议方法中创建一个临时地图,并填充所有数据,如下所示:
HashMap<CellLocation, CellState> temporaryBoard = new HashMap<>();
temporaryBoard.put(CellLocation.TOP_LEFT,gameBoard.getCellState(CellLocation.TOP_LEFT));
temporaryBoard.put(CellLocation.TOP_CENTRE,gameBoard.getCellState(CellLocation.TOP_CENTRE));
temporaryBoard.put(CellLocation.TOP_RIGHT,gameBoard.getCellState(CellLocation.TOP_RIGHT));
temporaryBoard.put(CellLocation.CENTRE_LEFT,gameBoard.getCellState(CellLocation.CENTRE_LEFT));
temporaryBoard.put(CellLocation.CENTRE_CENTRE,gameBoard.getCellState(CellLocation.CENTRE_CENTRE));
temporaryBoard.put(CellLocation.CENTRE_RIGHT,gameBoard.getCellState(CellLocation.CENTRE_RIGHT));
temporaryBoard.put(CellLocation.BOTTOM_LEFT,gameBoard.getCellState(CellLocation.BOTTOM_LEFT));
temporaryBoard.put(CellLocation.BOTTOM_CENTRE,gameBoard.getCellState(CellLocation.BOTTOM_CENTRE));
temporaryBoard.put(CellLocation.BOTTOM_RIGHT,gameBoard.getCellState(CellLocation.BOTTOM_RIGHT));
所以我可以轻松地使用它。我不确定是否应该为自己制作一个临时游戏板。
任何想法都将不胜感激。
【问题讨论】:
-
我得到了完全相同的练习。你是被 T*****k 公司录用的吗?
标签: java algorithm tic-tac-toe