Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface Player {
- void takeTurn(GameBoard board, GameLogic logic);
- void lostGame(GameBoard board, GameLogic logic);
- void wonGame(GameBoard board, GameLogic logic);
- void drawGame(GameBoard board, GameLogic logic);
- void startGame(GameBoard board, GameLogic logic);
- void randomChoice(ComputerPlayer player);
- }
- public abstract class ComputerPlayer implements Player {
- public int x;
- public int y;
- public void printBoard(GameBoard board, GameLogic logic)
- {
- for (int y=0; y<3; y++)
- {
- for (int x=0; x<3; x++)
- {
- int[] pos = {x,y};
- ComputerPlayer curr = board.getPos(pos);
- }
- }
- }
- public void randomPlayer(){
- x = (int) (Math.random() * 300);
- y = (int) (Math.random() * 250);
- }
- public void randomChoice(ComputerPlayer player){
- int smartNaiveChoice = (int)(1 + Math.random() * 2);
- if (smartNaiveChoice == 1){
- new SmartPlayer();
- }
- else if (smartNaiveChoice == 2){
- new NaivePlayer();
- }
- }
- public void startGame(GameBoard board, GameLogic logic){
- printBoard(board, logic);
- }
- public void lostGame(GameBoard board, GameLogic logic) {
- printBoard(board, logic);
- }
- public void wonGame(GameBoard board, GameLogic logic) {
- printBoard(board, logic);
- }
- public void drawGame(GameBoard board, GameLogic logic) {
- printBoard(board, logic);
- }
- public void takeTurn(GameBoard board, GameLogic logic) {
- printBoard(board, logic);
- }
- }
- public class NaivePlayer extends ComputerPlayer {
- private int randomPosPart(int min, int max)
- {
- return min + (int)(Math.random() * ((max - min) + 1));
- }
- private int[] randomPos()
- {
- int[] pos = {
- randomPosPart(0,2),
- randomPosPart(0,2)
- };
- return pos;
- }
- private int[] generateMovePos(GameBoard board, GameLogic logic)
- {
- return randomPos();
- }
- public void takeTurn(GameBoard board, GameLogic logic) {
- int[] pos = generateMovePos(board, logic);
- boolean valid = logic.move(this, pos);
- }
- }
- public class SmartPlayer extends ComputerPlayer {
- private int randomPosPart(int min, int max)
- {
- return min + (int)(Math.random() * ((max - min) + 1));
- }
- private int[] randomPos()
- {
- int[] pos = {
- randomPosPart(0,2),
- randomPosPart(0,2)
- };
- return pos;
- }
- public int[] generateMovePos(GameBoard board, GameLogic logic){
- if ((board.getPos(new int[]{0, 0}) == board.getPos(new int[]{1,
- 0}))){
- int[] pos = {2, 0};
- }
- else if ((board.getPos(new int[]{0, 0}) == board.getPos(new
- int[]{2, 0}))){
- int[] pos = {1, 0};
- }
- else if ((board.getPos(new int[]{1, 0}) == board.getPos(new
- int[]{2, 0}))){
- int[] pos = {0, 0};
- }
- else if ((board.getPos(new int[]{0, 1}) == board.getPos(new
- int[]{1, 1}))){
- int[] pos = {2, 1};
- }
- else if ((board.getPos(new int[]{0, 1}) == board.getPos(new
- int[]{2, 1}))){
- int[] pos = {1, 1};
- }
- else if ((board.getPos(new int[]{1, 1}) == board.getPos(new
- int[]{2, 1}))){
- int[] pos = {0, 1};
- }
- else if ((board.getPos(new int[]{0, 2}) == board.getPos(new
- int[]{1, 2}))){
- int[] pos = {2, 2};
- }
- else if ((board.getPos(new int[]{1, 2}) == board.getPos(new
- int[]{2, 2}))){
- int[] pos = {0, 2};
- }
- else if ((board.getPos(new int[]{0, 2}) == board.getPos(new
- int[]{2, 2}))){
- int[] pos = {1, 2};
- }
- else if ((board.getPos(new int[]{0, 0}) == board.getPos(new
- int[]{0, 1}))){
- int[] pos = {0, 2};
- }
- else if ((board.getPos(new int[]{0, 1}) == board.getPos(new
- int[]{0, 2}))){
- int[] pos = {0, 0};
- }
- else if ((board.getPos(new int[]{0, 0}) == board.getPos(new
- int[]{0, 2}))){
- int[] pos = {0, 1};
- }
- else if ((board.getPos(new int[]{1, 1}) == board.getPos(new
- int[]{1, 2}))){
- int[] pos = {1, 0};
- }
- else if ((board.getPos(new int[]{1, 0}) == board.getPos(new
- int[]{1, 2}))){
- int[] pos = {1, 1};
- }
- else if ((board.getPos(new int[]{1, 0}) == board.getPos(new
- int[]{1, 1}))){
- int[] pos = {1, 2};
- }
- else if ((board.getPos(new int[]{2, 0}) == board.getPos(new
- int[]{2, 1}))){
- int[] pos = {2, 2};
- }
- else if ((board.getPos(new int[]{2, 1}) == board.getPos(new
- int[]{2, 2}))){
- int[] pos = {2, 0};
- }
- else if ((board.getPos(new int[]{2, 0}) == board.getPos(new
- int[]{2, 2}))){
- int[] pos = {2, 1};
- }
- else if ((board.getPos(new int[]{0, 0}) == board.getPos(new
- int[]{1, 1}))){
- int[] pos = {2, 2};
- }
- else if ((board.getPos(new int[]{1, 1}) == board.getPos(new
- int[]{2, 2}))){
- int[] pos = {0, 0};
- }
- else if ((board.getPos(new int[]{0, 0}) == board.getPos(new
- int[]{2, 2}))){
- int[] pos = {1, 1};
- }
- else if ((board.getPos(new int[]{0, 2}) == board.getPos(new
- int[]{2, 0}))){
- int[] pos = {1, 1};
- }
- else if ((board.getPos(new int[]{1, 1}) == board.getPos(new
- int[]{2, 0}))){
- int[] pos = {0, 2};
- }
- else if((board.getPos(new int[]{1, 1}) == board.getPos(new
- int[]{0, 2}))){
- int[] pos = {2, 0};
- }
- else{
- return randomPos();
- }
- return null;
- }
- public void takeTurn(GameBoard board, GameLogic logic) {
- int[] pos = generateMovePos(board, logic);
- boolean valid = logic.move(this, pos);
- }
Add Comment
Please, Sign In to add comment