Xiangiqgame
AI engine for Xiangqi
Loading...
Searching...
No Matches
piece_points.py
Go to the documentation of this file.
1"""
2No longer used, but keep for reference: classes for handling piece points.
3"""
4
5from typing import Dict
6
7import numpy as np
8from xiangqi_bindings import PieceColor, PieceType
9
10base_pts_icga_2004 = {
11 PieceType.kGen: 6000,
12 PieceType.kAdv: 120,
13 PieceType.kEle: 120,
14 PieceType.kCha: 600,
15 PieceType.kHor: 270,
16 PieceType.kCan: 285,
17 PieceType.kSol: 30
18}
19
21
22 def __init__(self, piece_vals: Dict[int, int]):
23 # assert set(piece_vals.keys()) == set(PieceType) - {PieceType.kNnn}
24 self._piece_vals = piece_vals
25
26 @property
27 def vals(self):
28 return self._piece_vals
29
30
32
34 self,
35 pts_arrays_black: Dict[int, np.array],
36 pts_arrays_red: Dict[int, np.array] = None
37 ):
38 # assert set(pts_arrays_black.keys()) == set(PieceType) - {PieceType.kNnn}
39 if pts_arrays_red:
40 pass
41 # assert set(pts_arrays_red.keys()) == set(PieceType) - {PieceType.kNnn}
42 if pts_arrays_red is None:
43 pts_arrays_red = {piece_type: np.flip(pts_array, axis=0) for
44 piece_type, pts_array in pts_arrays_black.items()}
45 self._pts_arrays = {
46 PieceColor.kRed: pts_arrays_red,
47 PieceColor.kBlk: pts_arrays_black}
48
49 @property
50 def vals(self):
51 return self._pts_arrays
52
53
54general_position_icga_2004 = np.zeros(90).reshape((10, 9))
55advisor_position_icga_2004 = np.zeros(90).reshape((10, 9))
56elephant_position_icga_2004 = np.zeros(90).reshape((10, 9))
57
58chariot_position_icga_2004 = np.array([
59 [-2, 10, 6, 14, 12, 14, 6, 10, -2],
60 [8, 4, 8, 16, 8, 16, 8, 4, 8],
61 [4, 8, 6, 14, 12, 14, 6, 8, 4],
62 [6, 10, 8, 14, 14, 14, 8, 10, 6],
63 [12, 16, 14, 20, 20, 20, 14, 16, 12],
64 [12, 14, 12, 18, 18, 18, 12, 14, 12],
65 [12, 18, 16, 22, 22, 22, 16, 18, 12],
66 [12, 12, 12, 18, 18, 18, 12, 12, 12],
67 [16, 20, 18, 24, 26, 24, 18, 20, 16],
68 [14, 14, 12, 18, 16, 18, 12, 14, 14]
69])
70
71horse_position_icga_2004 = np.array([
72 [0, -4, 0, 0, 0, 0, 0, -4, 0],
73 [0, 2, 4, 4, -2, 4, 4, 2, 0],
74 [4, 2, 8, 8, 4, 8, 8, 2, 4],
75 [2, 6, 8, 6, 10, 6, 8, 6, 2],
76 [4, 12, 16, 14, 12, 14, 16, 12, 4],
77 [6, 16, 14, 18, 16, 18, 14, 16, 6],
78 [8, 24, 18, 24, 20, 24, 18, 24, 8],
79 [12, 14, 16, 20, 18, 20, 16, 14, 12],
80 [4, 10, 28, 16, 8, 16, 28, 10, 4],
81 [4, 8, 16, 12, 4, 12, 16, 8, 4]
82])
83
84cannon_position_icga_2004 = np.array([
85 [0, 0, 2, 6, 6, 6, 2, 0, 0],
86 [0, 2, 4, 6, 6, 6, 4, 2, 0],
87 [4, 0, 8, 6, 10, 6, 8, 0, 4],
88 [0, 0, 0, 2, 4, 2, 0, 0, 0],
89 [-2, 0, 4, 2, 6, 2, 4, 0, -2],
90 [0, 0, 0, 2, 8, 2, 0, 0, 0],
91 [0, 0, -2, 4, 10, 4, -2, 0, 0],
92 [2, 2, 0, -10, -8, -10, 0, 2, 2],
93 [2, 2, 0, -4, -14, -4, 0, 2, 2],
94 [6, 4, 0, -10, -12, -10, 0, 4, 6]
95])
96
97soldier_position_icga_2004 = np.array([
98 [0, 0, 0, 0, 0, 0, 0, 0, 0],
99 [0, 0, 0, 0, 0, 0, 0, 0, 0],
100 [0, 0, 0, 0, 0, 0, 0, 0, 0],
101 [0, 0, -2, 0, 0, 0, -2, 0, 0],
102 [2, 0, 8, 0, 8, 0, 8, 0, 2],
103 [6, 12, 18, 18, 20, 18, 18, 12, 6],
104 [10, 20, 30, 34, 40, 34, 30, 20, 10],
105 [14, 26, 42, 60, 80, 60, 42, 26, 14],
106 [18, 36, 56, 80, 120, 80, 56, 36, 18],
107 [0, 3, 6, 9, 12, 9, 6, 3, 0]
108])
109
110position_points_icga_2004 = {
111 PieceType.kGen: general_position_icga_2004,
112 PieceType.kAdv: advisor_position_icga_2004,
113 PieceType.kEle: elephant_position_icga_2004,
114 PieceType.kCha: chariot_position_icga_2004,
115 PieceType.kHor: horse_position_icga_2004,
116 PieceType.kCan: cannon_position_icga_2004,
117 PieceType.kSol: soldier_position_icga_2004
118}
119
120
121DEFAULT_BASE_POINTS = BasePoints(piece_vals=base_pts_icga_2004)
122DEFAULT_POSITION_POINTS = PositionPts(
123 pts_arrays_black=position_points_icga_2004)
124
125
def __init__(self, Dict[int, int] piece_vals)
Definition: piece_points.py:22
def __init__(self, Dict[int, np.array] pts_arrays_black, Dict[int, np.array] pts_arrays_red=None)
Definition: piece_points.py:37