Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. package sample;
  2.  
  3.  
  4.  
  5. class LinkedList {
  6. Node head;
  7. public boolean turn;
  8. public static int search=6;
  9. public static Model model;
  10. public static Update update;
  11. public int [][]game;
  12. public static int t=0;
  13. LinkedList(Model model, Update update) {
  14. this.model = model;
  15. this.update = update;
  16. head = new Node();
  17. game=model.getGridAllDiscs();
  18. turn=model.isPlayerTurn();
  19. if(turn==false){
  20. createTree(game);
  21. }
  22. }
  23. LinkedList(int[][]grid){
  24. createTree(grid);
  25. }
  26.  
  27. void createTree(int[][]grid){
  28. game=grid;
  29. addAtColumn(grid,head);
  30. }
  31.  
  32. void addAtColumn( int[][]grid,Node node) {
  33. Node pointer=node;
  34. if(search>0) {
  35. for (int i = 0; i < model.getXLength(); i++) {
  36. t=t+1;
  37. System.out.println(t);
  38. Node tmp = new Node();
  39. tmp.coordinate = getCoordinate(grid, i);
  40. System.out.println(tmp.coordinate);
  41. tmp.currentGame = placeDisc(tmp.coordinate, grid);
  42. pointer.moves[i] = tmp;
  43. addAtColumn(tmp.currentGame, tmp );
  44.  
  45. }
  46. search=search-1;
  47. }
  48. System.out.println(t);
  49. }
  50. public int getHeight(int[][] grid, int column){
  51. int height=5;
  52. for (int i = 0; i < model.getYLength(); i++) {
  53. if (grid[column][i] != 0) {
  54. height=height-1;
  55. }
  56. }
  57. return height;
  58. }
  59.  
  60. public String getCoordinate(int[][]grid,int n){
  61. String coords=n+","+getHeight(grid,n);
  62. return coords;
  63. }
  64.  
  65. public int[][]placeDisc(String coords, int[][]grid){
  66. int[][]game=grid;
  67. String temp[]=coords.split(",");
  68. if(turn==false){
  69. game[Integer.parseInt(temp[0])][Integer.parseInt(temp[1])]=2;
  70. }else{
  71. game[Integer.parseInt(temp[0])][Integer.parseInt(temp[1])]=1;
  72. }
  73. return game;
  74. }
  75.  
  76.  
  77. }
  78.  
  79.  
  80. class Node{
  81. String coordinate;
  82. int value;
  83. int[][]currentGame=new int[7][6];
  84. Node moves[]=new Node[7];
  85.  
  86. public void setGame(int[][]grid){
  87. System.out.println(coordinate);
  88. currentGame=grid;
  89. }
  90. public int[][]getCurrentGame(){
  91. return currentGame;
  92. }
  93.  
  94.  
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement