def F(self, i, j, m, x): if (i == 0 or j == 0): return 0 if (m > j or m > i): return 0 if (abs(x) > m): return 0 W_tmp = vector_min(self.W, j)[:i] T_tmp = vector_min(self.T, j)[:i] if (max_rook_num(W_tmp) < x): return 0 if (-max_rook_num(L_vector(W_tmp, T_tmp, j)) > x): return 0 if (is_single_type(W_tmp, T_tmp, j)): return F_0(i, j, m, x, what_single_type(W_tmp, T_tmp, j)) if (W_tmp[-1] == j): ## corner is in W width = width_to_remove(W_tmp) maximum_rooks_in_right = min(width, j) sum = 0 for r in range(min(maximum_rooks_in_right, m) + 1): sum += self.values[i - width, j, m - r, x - r] * single_type_rectangle( width, j - (m - r), r) return sum if (T_tmp[-1] < j): ## corner is in L height = j - T_tmp[-1] maximum_rooks_in_top = min(i, height) sum = 0 for r in range(min(maximum_rooks_in_top, m) + 1): F_tmp = self.values[i, j - height, m - r, x + r] top = single_type_rectangle(i - (m - r), height, r) sum += F_tmp * top return sum # REMISY if (is_double_type_with_tie(W_tmp, T_tmp, j)): return F_1(i, j, m, x, W_tmp, T_tmp, what_double_type(W_tmp, T_tmp, j)) if (T_tmp[-1] == j): ## corner is in T width = width_to_remove(T_tmp) height = T_tmp[-1] - W_tmp[-1] maximum_rooks_in_top = min(i - width, height) maximum_rooks_in_right = min(width, j - height) maximum_rooks_in_corner = min(width, height) sum = 0 for r_3 in range(min(maximum_rooks_in_top, m) + 1): for r_2 in range(min(maximum_rooks_in_corner, m) + 1): for r_1 in range(min(maximum_rooks_in_right, m) + 1): if (r_1 + r_2 + r_3 <= m): r_4 = m - r_1 - r_2 - r_3 F_tmp = self.values[i - width, j - height, r_4, x - r_1 + r_3] top = single_type_rectangle( i - width - r_4, height, r_3) corner = single_type_rectangle( width, height - r_3, r_2) right = single_type_rectangle( width - r_2, j - height - r_4, r_1) sum += F_tmp * top * corner * right return sum
def rotate_clash_matrix(self): tmp_W = self.fields_number - np.flip(self.T, 0) ## to jest nowe W self.T = self.fields_number - np.flip(self.W, 0) ## to jest nowe T self.W = tmp_W self.knots = find_knots(self.W, self.T) self.m_constraints = find_m_constraints(self.knots, self.fields_number).astype(int) self.x_max = np.max(max_rook_num(self.W)) ## i, j, m, x order self.values = np.zeros((self.fields_number + 1, self.fields_number + 1, self.fields_number + 1, self.x_max + 1))
def reload(self, A, B): self.A = A self.B = B self.fields_number = A.shape[0] if(int(self.fields_number / 2) * 2 == self.fields_number): print("Even number of fields!!!") return self.W, self.T = single_payoff_matrix_vectors(A, B) self.knots = find_knots(self.W, self.T) self.m_constraints = find_m_constraints(self.knots, self.fields_number).astype(int) self.x_max = max_rook_num(self.W) ## i, j, m, x order self.values = np.zeros((self.fields_number + 1, self.fields_number + 1, self.fields_number + 1, self.x_max + 1))
def F(i, j, m, x, W, T): if (i == 0 or j == 0): return 0 if (m > j or m > i): return 0 if (abs(x) > m): return 0 if (max_rook_num(W) < x): return 0 if (-max_rook_num(L_vector(W, T, j)) > x): return 0 if (is_single_type(W, T, j)): return F_0(i, j, m, x, what_single_type(W, T, j)) if (W[-1] == j): ## corner is in W # print("W CORNER") width = width_to_remove(W) maximum_rooks_in_right = min(width, j) sum = 0 for r in range(min(maximum_rooks_in_right, m) + 1): sum += F(i - width, j, m - r, x - r, W[:-width], T[:-width]) * single_type_rectangle( width, j - (m - r), r) return sum if (T[-1] < j): ## corner is in L # print("L CORNER") height = j - T[-1] maximum_rooks_in_top = min(i, height) sum = 0 for r in range(min(maximum_rooks_in_top, m) + 1): F_tmp = F(i, j - height, m - r, x + r, vector_min(W, j - height), vector_min(T, j - height)) top = single_type_rectangle(i - (m - r), height, r) sum += F_tmp * top ## TODO czy nie powinniśmy zmniejszać W i T? done, bez zmian return sum # REMISY if (is_double_type_with_tie(W, T, j)): return F_1(i, j, m, x, W, T, what_double_type(W, T, j)) if (T[-1] == j): ## corner is in T # print("WESZLIŚMY W REMISY") width = width_to_remove(T) height = T[-1] - W[-1] maximum_rooks_in_top = min(i - width, height) maximum_rooks_in_right = min(width, j - height) maximum_rooks_in_corner = min(width, height) sum = 0 for r_3 in range(min(maximum_rooks_in_top, m) + 1): for r_2 in range(min(maximum_rooks_in_corner, m) + 1): for r_1 in range(min(maximum_rooks_in_right, m) + 1): if (r_1 + r_2 + r_3 <= m): r_4 = m - r_1 - r_2 - r_3 F_tmp = F(i - width, j - height, r_4, x - r_1 + r_3, vector_min(W[:-width], j - height), vector_min(T[:-width], j - height)) top = single_type_rectangle(i - width - r_4, height, r_3) corner = single_type_rectangle(width, height - r_3, r_2) right = single_type_rectangle(width - r_2, j - height - r_4, r_1) sum += F_tmp * top * corner * right ## TODO czy nie powinniśmy zmniejszać W i T? done, bez zmian return sum