Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.68 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. package cz.cvut.agents.rph.reversi.players.nguyet31;
  8.  
  9. import cz.cvut.agents.rph.reversi.ReversiMove;
  10. import cz.cvut.agents.rph.reversi.ReversiPlayer;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13.  
  14. /**
  15. *
  16. * @author ASUS
  17. */
  18. public class MyPlayer extends ReversiPlayer {
  19.  
  20. @Override
  21. public String getName() {
  22. return "nguyet31";
  23. }
  24.  
  25. @Override
  26. public ReversiMove makeNextMove(int[][] board) {
  27. int myColor = this.getMyColor();
  28. int opponentsColor = this.getOpponentColor();
  29. System.out.println(myColor);
  30.  
  31.  
  32.  
  33.  
  34. return new ReversiMove(3,3);
  35. }
  36.  
  37. public boolean isValidMove (int[][] board, int playerColor) {
  38. // potřebuju aby mi to zjistilo, jestli místo, kde chci položit kámen, už někdo stojí já nebo opponent
  39. if ((playerColor == this.getMyColor()) || (playerColor == this.getOpponentColor())){
  40. return false;
  41. }
  42. if ((board)) {
  43.  
  44. }
  45. else return true;
  46. }
  47.  
  48. public void validMoves(int[][] board, int playerColor) {
  49.  
  50.  
  51. /*
  52. int position = board [3][3]; --- vrací tah s kameny
  53. if (position == getMyColor())
  54. else if (position == getOpponentsColor())
  55.  
  56.  
  57. List <Position> positions = getAllAvailablePositions (board); -- vrati mi to list pozic x,y definované v Position
  58.  
  59. private List <Position> getAllAvailablePositions (int[][] board)
  60. // vytvoreni prazdneho listu pozic
  61. // prochazim polem
  62. // pro kazde policko check
  63. boolean available = checkPosition(x,y,board);
  64. // pokud OK -> pridam pozici do listu
  65. // vratim list pozic
  66. return null
  67.  
  68. private class Position
  69. private int x;
  70. private int y;
  71.  
  72.  
  73. heuristika
  74. -- obrazky na tabletu
  75. -- spis se soustredit na pozice nez na to kolik kamenů vemu
  76. -- zkusit naprogramovat algoritmus, ktery hleda cestu (od zacatku k cili a naopak)
  77.  
  78. */
  79. List<ReversiMove> moves = new ArrayList();
  80. for (int i = 0; i < board.length; i++) {
  81.  
  82. }
  83.  
  84. for (int x = 0; x < board[0].length; x++) {
  85. for (int y = 0; y < board[0].length; y++) {
  86. if (board[x][y] == myColor) {
  87.  
  88. if (isInFrontOfWall(board, x, y)){
  89. if (x==0){
  90.  
  91. }
  92. if (y==0) {
  93.  
  94. }
  95. if (x==board[0].length){
  96.  
  97. }
  98. if (y==board[0].length){
  99.  
  100. }
  101.  
  102.  
  103.  
  104. }
  105.  
  106.  
  107.  
  108. }
  109. }
  110. }
  111.  
  112. }
  113.  
  114. // roh ---> spešl případ stěny
  115.  
  116. public boolean isInFrontOfWall(int[][] board, int x, int y) {
  117. if ((x == 0) || (y == 0) || (x == board[0].length) || (y == board[0].length)) {
  118. return true;
  119. }
  120. return false;
  121. }
  122.  
  123.  
  124. public boolean isInCorner(int[][] board, int x, int y) {
  125. if ((x == board[0].length) && (y == board[0].length)) {
  126.  
  127. return true;
  128.  
  129. }
  130. if ((x == 0) && (y == 0)) {
  131.  
  132. return true;
  133. }
  134.  
  135. if ((x == 0) && (y == board[0].length)) {
  136.  
  137. return true;
  138. }
  139.  
  140. if ((x == board[0].length) && (y == 0)) {
  141.  
  142. return true;
  143. }
  144. return false;
  145. }
  146.  
  147.  
  148. public boolean isCorrectMove(int[][] board, ReversiPlayer player, ReversiMove move)
  149. {
  150. if (move == null) {
  151. return false;
  152. }
  153. int x = move.getX();
  154. int y = move.getY();
  155. int color = player.getMyColor();
  156. if ((x < 0) || (x >= this.width) || (y < 0) || (y >= this.height)) {
  157. return false;
  158. }
  159. if (board[x][y] >= 0) {
  160. return false;
  161. }
  162. boolean direction = false;
  163. direction |= isCorrectMoveInDirection(board, color, 1, 0, x, y);
  164. direction |= isCorrectMoveInDirection(board, color, 1, 1, x, y);
  165. direction |= isCorrectMoveInDirection(board, color, 0, 1, x, y);
  166. direction |= isCorrectMoveInDirection(board, color, -1, 1, x, y);
  167. direction |= isCorrectMoveInDirection(board, color, -1, 0, x, y);
  168. direction |= isCorrectMoveInDirection(board, color, -1, -1, x, y);
  169. direction |= isCorrectMoveInDirection(board, color, 0, -1, x, y);
  170. direction |= isCorrectMoveInDirection(board, color, 1, -1, x, y);
  171.  
  172. return direction;
  173. }
  174.  
  175. private boolean isCorrectMoveInDirection(int[][] board, int player, int dirX, int dirY, int x, int y)
  176. {
  177. boolean neighbourOpponent = false;
  178. boolean endingMyStone = false;
  179. while (!endingMyStone)
  180. {
  181. x += dirX;
  182. y += dirY;
  183. if ((x < 0) || (x >= this.width) || (y < 0) || (y >= this.height)) {
  184. return false;
  185. }
  186. int color = board[x][y];
  187. if (color < 0) {
  188. return false;
  189. }
  190. if (color != player) {
  191. neighbourOpponent = true;
  192. } else {
  193. endingMyStone = true;
  194. }
  195. }
  196. if ((neighbourOpponent) && (endingMyStone)) {
  197. return true;
  198. }
  199. return false;
  200. }
  201.  
  202.  
  203. }
  204.  
  205.  
  206. /*
  207.  
  208. package cz.cvut.agents.rph.reversi.players;
  209.  
  210. import cz.cvut.agents.rph.reversi.ReversiMove;
  211. import cz.cvut.agents.rph.reversi.ReversiPlayer;
  212. import java.io.PrintStream;
  213.  
  214. public final class DummyPlayer
  215. extends ReversiPlayer
  216. {
  217. private final int RANDOM_MOVES_NUMBER = 1000;
  218.  
  219. public String getName()
  220. {
  221. return "Dummy Player";
  222. }
  223.  
  224. public ReversiMove makeNextMove(int[][] board)
  225. {
  226. for (int i = 0; i < 1000; i++)
  227. {
  228. int randomX = (int)(Math.random() * this.width);
  229. int randomY = (int)(Math.random() * this.height);
  230. if (isCorrectMove(board, this, new ReversiMove(randomX, randomY))) {
  231. return new ReversiMove(randomX, randomY);
  232. }
  233. }
  234. for (int x = 0; x < this.width; x++) {
  235. for (int y = 0; y < this.height; y++)
  236. {
  237. if (isCorrectMove(board, this, new ReversiMove(x, y))) {
  238. return new ReversiMove(x, y);
  239. }
  240. System.out.println("Incorrect: " + x + "," + y);
  241. }
  242. }
  243. System.out.println("I don't know, beeee :(");
  244. return new ReversiMove(-1, -1);
  245. }
  246.  
  247. public boolean isCorrectMove(int[][] board, ReversiPlayer player, ReversiMove move)
  248. {
  249. if (move == null) {
  250. return false;
  251. }
  252. int x = move.getX();
  253. int y = move.getY();
  254. int color = player.getMyColor();
  255. if ((x < 0) || (x >= this.width) || (y < 0) || (y >= this.height)) {
  256. return false;
  257. }
  258. if (board[x][y] >= 0) {
  259. return false;
  260. }
  261. boolean direction = false;
  262. direction |= isCorrectMoveInDirection(board, color, 1, 0, x, y);
  263. direction |= isCorrectMoveInDirection(board, color, 1, 1, x, y);
  264. direction |= isCorrectMoveInDirection(board, color, 0, 1, x, y);
  265. direction |= isCorrectMoveInDirection(board, color, -1, 1, x, y);
  266. direction |= isCorrectMoveInDirection(board, color, -1, 0, x, y);
  267. direction |= isCorrectMoveInDirection(board, color, -1, -1, x, y);
  268. direction |= isCorrectMoveInDirection(board, color, 0, -1, x, y);
  269. direction |= isCorrectMoveInDirection(board, color, 1, -1, x, y);
  270.  
  271. return direction;
  272. }
  273.  
  274. private boolean isCorrectMoveInDirection(int[][] board, int player, int dirX, int dirY, int x, int y)
  275. {
  276. boolean neighbourOpponent = false;
  277. boolean endingMyStone = false;
  278. while (!endingMyStone)
  279. {
  280. x += dirX;
  281. y += dirY;
  282. if ((x < 0) || (x >= this.width) || (y < 0) || (y >= this.height)) {
  283. return false;
  284. }
  285. int color = board[x][y];
  286. if (color < 0) {
  287. return false;
  288. }
  289. if (color != player) {
  290. neighbourOpponent = true;
  291. } else {
  292. endingMyStone = true;
  293. }
  294. }
  295. if ((neighbourOpponent) && (endingMyStone)) {
  296. return true;
  297. }
  298. return false;
  299. }
  300. }
  301.  
  302. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement