Advertisement
Guest User

TestBot

a guest
Feb 17th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. using ConnectFour;
  2. using System;
  3.  
  4.  
  5. public class MarvinKirchnerBot : IPlayer
  6. {
  7. public readonly Random random = new Random();
  8.  
  9. public int Set(ConnectFour.Board board)
  10. {
  11.  
  12. //setColumnValue needed
  13. //while setolumn is the standard value
  14. //return of setColumnValue
  15. var setColumn = 0;
  16.  
  17. Occupants test = board.CurrentPlayer;
  18. // setColumn = board[x, y].Column;
  19.  
  20. for (int y = 0; y < board.Height; y++)
  21. {
  22. for (int x = 0; x < board.Width; x++)
  23. {
  24. if (!board.Columns[x].IsFull)
  25. {
  26. //if (board.Fields[x, y].Occupant != board.CurrentPlayer)
  27. //{
  28. if (x <= 1 && y < board.Height) //kein links
  29. {
  30.  
  31. if (board.Fields[x + 1, y].Occupant == Occupants.None)//wenn einen nach rechts frei ist, setze einen nach rechts
  32. {
  33. if (board.Fields[x, y].Occupant != test)
  34. {
  35. setColumn = board[x + 1, y].Column;
  36. }
  37. }
  38. else
  39. {
  40. if (board.Fields[x, y].Occupant != test)
  41. {
  42. setColumn = board[x, y - 1].Column; //top
  43. }
  44. }
  45.  
  46.  
  47.  
  48.  
  49. }
  50. else
  51. {
  52. if (x >= board.Width - 1 && x > 1) //kein rechts
  53. {
  54.  
  55. if (board.Fields[x - 1, y].Occupant == Occupants.None) //wenn einen nach links frei ist, setze dort hin
  56. {
  57. if (board.Fields[x , y].Occupant != test)
  58. {
  59. setColumn = board[x - 1, y].Column;
  60. }
  61. }
  62. else
  63. {
  64. if (board.Fields[x , y].Occupant != test)
  65. {
  66. setColumn = board[x, y - 1].Column;//top
  67. }
  68. }
  69. }
  70. else
  71. {
  72. if (board.Fields[x + 1, y].Occupant == Occupants.None)
  73. {
  74. //wenn einen nach rechts frei ist, setze einen nach rechts
  75. if (board.Fields[x , y].Occupant != board.CurrentPlayer)
  76. {
  77. setColumn = board[x + 1, y].Column;
  78. }
  79.  
  80. }
  81. else if (board.Fields[x - 1, y].Occupant == Occupants.None && x > 1)
  82. {
  83. //wenn einen nach links frei ist, setze dort hin
  84. if (board.Fields[x , y].Occupant != board.CurrentPlayer)
  85. {
  86. setColumn = board[x - 1, y].Column;
  87. }
  88.  
  89. }
  90. else
  91. {
  92. //top
  93. if (board.Fields[x, y].Occupant != board.CurrentPlayer)
  94. {
  95. setColumn = board[x, y - 1].Column;
  96. }
  97.  
  98. }
  99. }
  100. }
  101. //}
  102. }
  103.  
  104. }
  105. }
  106. return setColumn;
  107. }
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement