PageRenderTime 47ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

/CCJ/src/com/godpaper/model/ZobristKeysModel.as

http://chinesechessjam.googlecode.com/
ActionScript | 304 lines | 54 code | 4 blank | 246 comment | 7 complexity | 578a54c28ce3c1b24adc392c7a31f91d MD5 | raw file
  1. package com.godpaper.model
  2. {
  3. import com.godpaper.consts.ZobristConstants;
  4. import com.godpaper.errors.CcjErrors;
  5. import com.godpaper.model.vos.ZobristKeyVO;
  6. import com.godpaper.utils.LogUtil;
  7. import com.lookbackon.ds.ZobristHashTable;
  8. import de.polygonal.ds.Array3;
  9. import de.polygonal.ds.HashTable;
  10. import de.polygonal.math.PM_PRNG;
  11. import mx.logging.ILogger;
  12. /**
  13. * A singleton model hold all Chess Board's tag info for Chess HistoryTable/OpeningBook.
  14. *
  15. * @author Knight.zhou
  16. *
  17. */
  18. public class ZobristKeysModel
  19. {
  20. //--------------------------------------------------------------------------
  21. //
  22. // Variables
  23. //
  24. //--------------------------------------------------------------------------
  25. //Singleton instance of ZobristKeysModel;
  26. private static var instance:ZobristKeysModel;
  27. //reds
  28. /*private var _redRook:ZobristKeyVO = new ZobristKeyVO();
  29. private var _redKnight:ZobristKeyVO = new ZobristKeyVO();
  30. private var _redBishop:ZobristKeyVO = new ZobristKeyVO();
  31. private var _redOffical:ZobristKeyVO = new ZobristKeyVO();
  32. private var _redMarshal:ZobristKeyVO = new ZobristKeyVO();
  33. private var _redCannon:ZobristKeyVO = new ZobristKeyVO();
  34. private var _redPawn:ZobristKeyVO = new ZobristKeyVO();
  35. private var _reds:ZobristKeyVO = new ZobristKeyVO();*/
  36. //blues
  37. /*private var _blueRook:ZobristKeyVO = new ZobristKeyVO();
  38. private var _blueKnight:ZobristKeyVO = new ZobristKeyVO();
  39. private var _blueBishop:ZobristKeyVO = new ZobristKeyVO();
  40. private var _blueOffical:ZobristKeyVO = new ZobristKeyVO();
  41. private var _blueMarshal:ZobristKeyVO = new ZobristKeyVO();
  42. private var _blueCannon:ZobristKeyVO = new ZobristKeyVO();
  43. private var _bluePawn:ZobristKeyVO = new ZobristKeyVO();
  44. private var _blues:ZobristKeyVO = new ZobristKeyVO();*/
  45. private var _board:ZobristKeyVO = new ZobristKeyVO();
  46. //----------------------------------
  47. // CONSTANTS
  48. //----------------------------------
  49. private static const LOG:ILogger = LogUtil.getLogger(ZobristKeysModel);
  50. //generation.
  51. //TODO.other structs.
  52. //--------------------------------------------------------------------------
  53. //
  54. // Constructor
  55. //
  56. //--------------------------------------------------------------------------
  57. public function ZobristKeysModel(access:Private)
  58. {
  59. if (access != null) {
  60. if (instance == null) {
  61. instance=this;
  62. }
  63. } else {
  64. throw new CcjErrors(CcjErrors.INITIALIZE_SINGLETON_CLASS);
  65. }
  66. //static constructor block
  67. //ref:http://mediocrechess.blogspot.com/2007/01/guide-zobrist-keys.html
  68. var pm_pgn:PM_PRNG = new PM_PRNG();
  69. //board(reds and blues).
  70. _board.position.setXs(0,[pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt()]);
  71. _board.position.setXs(1,[pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt()]);
  72. _board.position.setXs(2,[pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt()]);
  73. _board.position.setXs(3,[pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt()]);
  74. _board.position.setXs(4,[pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt()]);
  75. _board.position.setXs(5,[pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt()]);
  76. _board.position.setXs(6,[pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt()]);
  77. _board.position.setXs(7,[pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt()]);
  78. _board.position.setXs(8,[pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt()]);
  79. _board.position.setXs(9,[pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt(),pm_pgn.nextInt()]);
  80. }
  81. //--------------------------------------------------------------------------
  82. //
  83. // Properties
  84. //
  85. //--------------------------------------------------------------------------
  86. /*
  87. //----------------------------------
  88. // bluePawn
  89. //----------------------------------
  90. public function get bluePawn():ZobristKeyVO
  91. {
  92. return _bluePawn;
  93. }
  94. public function set bluePawn(value:ZobristKeyVO):void
  95. {
  96. _bluePawn = value;
  97. }
  98. //----------------------------------
  99. // blueCannon
  100. //----------------------------------
  101. public function get blueCannon():ZobristKeyVO
  102. {
  103. return _blueCannon;
  104. }
  105. public function set blueCannon(value:ZobristKeyVO):void
  106. {
  107. _blueCannon = value;
  108. }
  109. //----------------------------------
  110. // blueMarshal
  111. //----------------------------------
  112. public function get blueMarshal():ZobristKeyVO
  113. {
  114. return _blueMarshal;
  115. }
  116. public function set blueMarshal(value:ZobristKeyVO):void
  117. {
  118. _blueMarshal = value;
  119. }
  120. //----------------------------------
  121. // blueOffical
  122. //----------------------------------
  123. public function get blueOffical():ZobristKeyVO
  124. {
  125. return _blueOffical;
  126. }
  127. public function set blueOffical(value:ZobristKeyVO):void
  128. {
  129. _blueOffical = value;
  130. }
  131. //----------------------------------
  132. // blueBishop
  133. //----------------------------------
  134. public function get blueBishop():ZobristKeyVO
  135. {
  136. return _blueBishop;
  137. }
  138. public function set blueBishop(value:ZobristKeyVO):void
  139. {
  140. _blueBishop = value;
  141. }
  142. //----------------------------------
  143. // blueKnight
  144. //----------------------------------
  145. public function get blueKnight():ZobristKeyVO
  146. {
  147. return _blueKnight;
  148. }
  149. public function set blueKnight(value:ZobristKeyVO):void
  150. {
  151. _blueKnight = value;
  152. }
  153. //----------------------------------
  154. // blueRook
  155. //----------------------------------
  156. public function get blueRook():ZobristKeyVO
  157. {
  158. return _blueRook;
  159. }
  160. public function set blueRook(value:ZobristKeyVO):void
  161. {
  162. _blueRook = value;
  163. }
  164. //----------------------------------
  165. // redPawn
  166. //----------------------------------
  167. public function get redPawn():ZobristKeyVO
  168. {
  169. return _redPawn;
  170. }
  171. public function set redPawn(value:ZobristKeyVO):void
  172. {
  173. _redPawn = value;
  174. }
  175. //----------------------------------
  176. // redCannon
  177. //----------------------------------
  178. public function get redCannon():ZobristKeyVO
  179. {
  180. return _redCannon;
  181. }
  182. public function set redCannon(value:ZobristKeyVO):void
  183. {
  184. _redCannon = value;
  185. }
  186. //----------------------------------
  187. // redMarshal
  188. //----------------------------------
  189. public function get redMarshal():ZobristKeyVO
  190. {
  191. return _redMarshal;
  192. }
  193. public function set redMarshal(value:ZobristKeyVO):void
  194. {
  195. _redMarshal = value;
  196. }
  197. //----------------------------------
  198. // redOffical
  199. //----------------------------------
  200. public function get redOffical():ZobristKeyVO
  201. {
  202. return _redOffical;
  203. }
  204. public function set redOffical(value:ZobristKeyVO):void
  205. {
  206. _redOffical = value;
  207. }
  208. //----------------------------------
  209. // redBishop
  210. //----------------------------------
  211. public function get redBishop():ZobristKeyVO
  212. {
  213. return _redBishop;
  214. }
  215. public function set redBishop(value:ZobristKeyVO):void
  216. {
  217. _redBishop = value;
  218. }
  219. //----------------------------------
  220. // redKnight
  221. //----------------------------------
  222. public function get redKnight():ZobristKeyVO
  223. {
  224. return _redKnight;
  225. }
  226. public function set redKnight(value:ZobristKeyVO):void
  227. {
  228. _redKnight = value;
  229. }
  230. //----------------------------------
  231. // redRook
  232. //----------------------------------
  233. public function get redRook():ZobristKeyVO
  234. {
  235. return _redRook;
  236. }
  237. public function set redRook(value:ZobristKeyVO):void
  238. {
  239. _redRook = value;
  240. HistoryTableModel.getInstance().redRook.insert(ZobristConstants.RED_ROOK.key,value);
  241. }
  242. //----------------------------------
  243. // reds
  244. //----------------------------------
  245. public function get reds():ZobristKeyVO
  246. {
  247. return _reds;
  248. }
  249. public function set reds(value:ZobristKeyVO):void
  250. {
  251. _reds = value;
  252. //TODO:
  253. // HistoryTableModel.getInstance().reds.insert(ZobristConstants.RED_ROOK.key,value);
  254. }
  255. //----------------------------------
  256. // blues
  257. //----------------------------------
  258. public function get blues():ZobristKeyVO
  259. {
  260. return _blues;
  261. }
  262. public function set blues(value:ZobristKeyVO):void
  263. {
  264. _blues = value;
  265. //TODO:
  266. // HistoryTableModel.getInstance().blues.insert(ZobristConstants.RED_ROOK.key,value);
  267. }
  268. //--------------------------------------------------------------------------
  269. //
  270. // Methods
  271. //
  272. //--------------------------------------------------------------------------
  273. /**
  274. *
  275. * @return the singleton instance of ZobristKeysModel
  276. *
  277. */
  278. public static function getInstance():ZobristKeysModel
  279. {
  280. if (instance == null)
  281. {
  282. instance=new ZobristKeysModel(new Private());
  283. }
  284. return instance;
  285. }
  286. public function getZobristKey(type:String="board"):ZobristKeyVO
  287. {
  288. //TODO:every key type such as (Knight/Marshall..) should with his zobristKeyVO.
  289. //but now we just renturn all board zobristkey vo.
  290. return _board;
  291. }
  292. }
  293. }
  294. /**
  295. *Inner class which restricts construtor access to Private
  296. */
  297. internal class Private
  298. {
  299. }