Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package cz.cvut.agents.rph.reversi.players.nguyet31;
- import cz.cvut.agents.rph.reversi.ReversiMove;
- import cz.cvut.agents.rph.reversi.ReversiPlayer;
- import java.util.ArrayList;
- import java.util.List;
- /**
- *
- * @author ASUS
- */
- public class MyPlayer extends ReversiPlayer {
- @Override
- public String getName() {
- return "nguyet31";
- }
- @Override
- public ReversiMove makeNextMove(int[][] board) {
- int myColor = this.getMyColor();
- int opponentsColor = this.getOpponentColor();
- System.out.println(myColor);
- return new ReversiMove(3,3);
- }
- public boolean isValidMove (int[][] board, int playerColor) {
- // potřebuju aby mi to zjistilo, jestli místo, kde chci položit kámen, už někdo stojí já nebo opponent
- if ((playerColor == this.getMyColor()) || (playerColor == this.getOpponentColor())){
- return false;
- }
- if ((board)) {
- }
- else return true;
- }
- public void validMoves(int[][] board, int playerColor) {
- /*
- int position = board [3][3]; --- vrací tah s kameny
- if (position == getMyColor())
- else if (position == getOpponentsColor())
- List <Position> positions = getAllAvailablePositions (board); -- vrati mi to list pozic x,y definované v Position
- private List <Position> getAllAvailablePositions (int[][] board)
- // vytvoreni prazdneho listu pozic
- // prochazim polem
- // pro kazde policko check
- boolean available = checkPosition(x,y,board);
- // pokud OK -> pridam pozici do listu
- // vratim list pozic
- return null
- private class Position
- private int x;
- private int y;
- heuristika
- -- obrazky na tabletu
- -- spis se soustredit na pozice nez na to kolik kamenů vemu
- -- zkusit naprogramovat algoritmus, ktery hleda cestu (od zacatku k cili a naopak)
- */
- List<ReversiMove> moves = new ArrayList();
- for (int i = 0; i < board.length; i++) {
- }
- for (int x = 0; x < board[0].length; x++) {
- for (int y = 0; y < board[0].length; y++) {
- if (board[x][y] == myColor) {
- if (isInFrontOfWall(board, x, y)){
- if (x==0){
- }
- if (y==0) {
- }
- if (x==board[0].length){
- }
- if (y==board[0].length){
- }
- }
- }
- }
- }
- }
- // roh ---> spešl případ stěny
- public boolean isInFrontOfWall(int[][] board, int x, int y) {
- if ((x == 0) || (y == 0) || (x == board[0].length) || (y == board[0].length)) {
- return true;
- }
- return false;
- }
- public boolean isInCorner(int[][] board, int x, int y) {
- if ((x == board[0].length) && (y == board[0].length)) {
- return true;
- }
- if ((x == 0) && (y == 0)) {
- return true;
- }
- if ((x == 0) && (y == board[0].length)) {
- return true;
- }
- if ((x == board[0].length) && (y == 0)) {
- return true;
- }
- return false;
- }
- public boolean isCorrectMove(int[][] board, ReversiPlayer player, ReversiMove move)
- {
- if (move == null) {
- return false;
- }
- int x = move.getX();
- int y = move.getY();
- int color = player.getMyColor();
- if ((x < 0) || (x >= this.width) || (y < 0) || (y >= this.height)) {
- return false;
- }
- if (board[x][y] >= 0) {
- return false;
- }
- boolean direction = false;
- direction |= isCorrectMoveInDirection(board, color, 1, 0, x, y);
- direction |= isCorrectMoveInDirection(board, color, 1, 1, x, y);
- direction |= isCorrectMoveInDirection(board, color, 0, 1, x, y);
- direction |= isCorrectMoveInDirection(board, color, -1, 1, x, y);
- direction |= isCorrectMoveInDirection(board, color, -1, 0, x, y);
- direction |= isCorrectMoveInDirection(board, color, -1, -1, x, y);
- direction |= isCorrectMoveInDirection(board, color, 0, -1, x, y);
- direction |= isCorrectMoveInDirection(board, color, 1, -1, x, y);
- return direction;
- }
- private boolean isCorrectMoveInDirection(int[][] board, int player, int dirX, int dirY, int x, int y)
- {
- boolean neighbourOpponent = false;
- boolean endingMyStone = false;
- while (!endingMyStone)
- {
- x += dirX;
- y += dirY;
- if ((x < 0) || (x >= this.width) || (y < 0) || (y >= this.height)) {
- return false;
- }
- int color = board[x][y];
- if (color < 0) {
- return false;
- }
- if (color != player) {
- neighbourOpponent = true;
- } else {
- endingMyStone = true;
- }
- }
- if ((neighbourOpponent) && (endingMyStone)) {
- return true;
- }
- return false;
- }
- }
- /*
- package cz.cvut.agents.rph.reversi.players;
- import cz.cvut.agents.rph.reversi.ReversiMove;
- import cz.cvut.agents.rph.reversi.ReversiPlayer;
- import java.io.PrintStream;
- public final class DummyPlayer
- extends ReversiPlayer
- {
- private final int RANDOM_MOVES_NUMBER = 1000;
- public String getName()
- {
- return "Dummy Player";
- }
- public ReversiMove makeNextMove(int[][] board)
- {
- for (int i = 0; i < 1000; i++)
- {
- int randomX = (int)(Math.random() * this.width);
- int randomY = (int)(Math.random() * this.height);
- if (isCorrectMove(board, this, new ReversiMove(randomX, randomY))) {
- return new ReversiMove(randomX, randomY);
- }
- }
- for (int x = 0; x < this.width; x++) {
- for (int y = 0; y < this.height; y++)
- {
- if (isCorrectMove(board, this, new ReversiMove(x, y))) {
- return new ReversiMove(x, y);
- }
- System.out.println("Incorrect: " + x + "," + y);
- }
- }
- System.out.println("I don't know, beeee :(");
- return new ReversiMove(-1, -1);
- }
- public boolean isCorrectMove(int[][] board, ReversiPlayer player, ReversiMove move)
- {
- if (move == null) {
- return false;
- }
- int x = move.getX();
- int y = move.getY();
- int color = player.getMyColor();
- if ((x < 0) || (x >= this.width) || (y < 0) || (y >= this.height)) {
- return false;
- }
- if (board[x][y] >= 0) {
- return false;
- }
- boolean direction = false;
- direction |= isCorrectMoveInDirection(board, color, 1, 0, x, y);
- direction |= isCorrectMoveInDirection(board, color, 1, 1, x, y);
- direction |= isCorrectMoveInDirection(board, color, 0, 1, x, y);
- direction |= isCorrectMoveInDirection(board, color, -1, 1, x, y);
- direction |= isCorrectMoveInDirection(board, color, -1, 0, x, y);
- direction |= isCorrectMoveInDirection(board, color, -1, -1, x, y);
- direction |= isCorrectMoveInDirection(board, color, 0, -1, x, y);
- direction |= isCorrectMoveInDirection(board, color, 1, -1, x, y);
- return direction;
- }
- private boolean isCorrectMoveInDirection(int[][] board, int player, int dirX, int dirY, int x, int y)
- {
- boolean neighbourOpponent = false;
- boolean endingMyStone = false;
- while (!endingMyStone)
- {
- x += dirX;
- y += dirY;
- if ((x < 0) || (x >= this.width) || (y < 0) || (y >= this.height)) {
- return false;
- }
- int color = board[x][y];
- if (color < 0) {
- return false;
- }
- if (color != player) {
- neighbourOpponent = true;
- } else {
- endingMyStone = true;
- }
- }
- if ((neighbourOpponent) && (endingMyStone)) {
- return true;
- }
- return false;
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement