Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ca.utoronto.utm.othello.model;
- public class PlayerStrategic extends Player {
- public PlayerStrategic(Othello othello, char player) {
- super(othello, player);
- }
- @Override
- public Move getMove() {
- PlayerGreedy greedyPlayer = new PlayerGreedy(this.othello, this.player);
- Move cornerMove = this.getCornerMove();
- Move sideMove = this.getSideMove();
- Move greedyMove = greedyPlayer.getMove();
- if (cornerMove != new Move(-1, -1)) {
- return cornerMove;
- }
- else if (sideMove != new Move(-1, -1)) {
- return sideMove;
- }
- else {
- return greedyMove;
- }
- }
- public Move getCornerMove() {
- Othello othelloCopy = othello.copy();
- //Used as an othello.board index
- int boardDim = Othello.DIMENSION - 1;
- int bestMoveCount = othelloCopy.getCount(this.player);
- Move bestMove = new Move(-1, -1);
- Move topLeft = new Move(0, 0);
- Move topRight = new Move(0, boardDim);
- Move bottomLeft = new Move(boardDim, 0);
- Move bottomRight = new Move(boardDim, boardDim);
- if (othelloCopy.move(topLeft.getRow(), topLeft.getCol()) &&
- othelloCopy.getCount(this.player)>bestMoveCount) {
- bestMoveCount = othelloCopy.getCount(this.player);
- bestMove = new Move(topLeft.getRow(), topLeft.getCol());
- }
- if (othelloCopy.move(topRight.getRow(), topRight.getCol()) &&
- othelloCopy.getCount(this.player)>bestMoveCount) {
- bestMoveCount = othelloCopy.getCount(this.player);
- bestMove = new Move(topRight.getRow(), topRight.getCol());
- }
- if (othelloCopy.move(bottomLeft.getRow(), bottomLeft.getCol()) &&
- othelloCopy.getCount(this.player)>bestMoveCount) {
- bestMoveCount = othelloCopy.getCount(this.player);
- bestMove = new Move(bottomLeft.getRow(), bottomLeft.getCol());
- }
- if (othelloCopy.move(topRight.getRow(), topRight.getCol()) &&
- othelloCopy.getCount(this.player)>bestMoveCount) {
- bestMoveCount = othelloCopy.getCount(this.player);
- bestMove = new Move(bottomRight.getRow(), bottomRight.getCol());
- }
- return bestMove;
- }
- //excludes corners intentionally, since corner move does that
- public Move getSideMove() {
- int boardDim = Othello.DIMENSION -1;
- Othello othelloCopy = othello.copy();
- Move bestMove = new Move(-1, -1);
- int bestMoveCount = othelloCopy.getCount(this.player);
- //check left wall
- for (int row = 1; row < boardDim - 1; row++) {
- othelloCopy = othello.copy();
- if(othelloCopy.move(row, 0) && othelloCopy.getCount(this.player)>bestMoveCount) {
- bestMoveCount = othelloCopy.getCount(this.player);
- bestMove = new Move(row, 0);
- }
- }
- //check upper wall
- for (int col = 1; col < boardDim - 1; col++) {
- othelloCopy = othello.copy();
- if(othelloCopy.move(0, col) && othelloCopy.getCount(this.player)>bestMoveCount) {
- bestMoveCount = othelloCopy.getCount(this.player);
- bestMove = new Move(0, col);
- }
- }
- //check right wall
- for (int row = 1; row < boardDim - 1; row++) {
- othelloCopy = othello.copy();
- if(othelloCopy.move(row, boardDim) && othelloCopy.getCount(this.player)>bestMoveCount) {
- bestMoveCount = othelloCopy.getCount(this.player);
- bestMove = new Move(row, boardDim);
- }
- }
- //check bottom wall
- for (int col = 1; col < boardDim - 1; col++) {
- othelloCopy = othello.copy();
- if(othelloCopy.move(boardDim, col) && othelloCopy.getCount(this.player)>bestMoveCount) {
- bestMoveCount = othelloCopy.getCount(this.player);
- bestMove = new Move(boardDim, col);
- }
- }
- return bestMove;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement