private void paint_all_moves(ChainsMas moves) { //заполнение всех ходов richTextBox1.Text = ""; foreach (Chain item_chain in moves.table_s_chains) { if (richTextBox1.Text != "") { richTextBox1.Text += "|\n"; } richTextBox1.Text += item_chain.ToString(); } //отрисовка только доступных foreach (Chain item in moves.get_all_high_important_chains()) { foreach (Move item_move in item.chain_s_moves) { item_move.cell_to.set_mark(true); } } }
private void pictureBox_Click(object sender, EventArgs e) { Cell temp = main.field_state[(int)(sender as PictureBox).Tag] as Cell; //режим редактирования if (edit_mode) { if (temp.color != edit_menu_cell.color || temp.king != edit_menu_cell.king) { temp.color = edit_menu_cell.color; temp.king = edit_menu_cell.king; temp.fill_image(); } } else //игровой режим { //клик на шашке if (temp.color != "empty") { bool mark = temp.marked; //чистим все отметки clear_all_marks(); //в зависимости от отметки, ставим\убираем ее temp.set_mark(!mark); if (temp.marked) { last_marked = temp; //рисуем доступные ходы mas = new ChainsMas(); calc_all_cell_moves(mas, temp, 0, main); paint_all_moves(mas); } else { last_marked = null; } } else //клик по пустому месту { //совершение хода if (last_marked != null) { System.Collections.ArrayList chains = mas.get_all_high_important_chains(); if (chains.Count > 0) { //поиск move foreach (Chain item in chains) { foreach (Move item_move in item.chain_s_moves) { //совершение move if (item_move.cell_to == temp) { if (!item_move.jump) { //простой ход clear_all_marks(); item_move.cell_to.color = (item.chain_s_moves[0] as Move).cell_from.color; item_move.cell_to.king = item_move.cell_from.king; item_move.cell_to.fill_image(); (item.chain_s_moves[0] as Move).cell_from.color = "empty"; (item.chain_s_moves[0] as Move).cell_from.king = false; (item.chain_s_moves[0] as Move).cell_from.fill_image(); } else { //прыжок со съеданием string first_color = (item.chain_s_moves[0] as Move).cell_from.color; foreach (Move internal_move in item.chain_s_moves) { clear_all_marks(); internal_move.cell_to.color = first_color; internal_move.cell_to.king = internal_move.cell_from.king; internal_move.cell_to.set_mark(false); internal_move.cell_from.color = "empty"; internal_move.cell_from.king = false; internal_move.cell_from.set_mark(false); foreach (Cell c in internal_move.eated_cells) { c.color = "empty"; c.king = false; c.fill_image(); } //рекурсивно, вызываем этот же метод, если ходы еще есть mas = new ChainsMas(); calc_all_cell_moves(mas, temp, 0, main); System.Collections.ArrayList imp_chains = mas.get_all_high_important_chains(); if (mas != null && imp_chains.Count > 0) { internal_move.cell_to.set_mark(true); pictureBox_Click(sender, new EventArgs()); } if (internal_move == item_move) { break; } } } return; } } } } } } } }
public void calc_all_cell_moves(ChainsMas temp, Cell c, int level, Field f) { if (c == null || temp == null) { return; } bool is_additional_jump = temp.is_last_chain_where_contain_cell_is_jump(c); string mine_first_color; bool mine_first_king; if (!is_additional_jump) { mine_first_color = c.color; mine_first_king = c.king; } else { mine_first_color = temp.get_first_color(); mine_first_king = temp.get_first_king(); } int[,] dir = { { -1, 1 }, { 1, 1 }, { -1, -1 }, { 1, -1 } }; //множественные ходы и множественная проверка if ( (c.king && русскиеToolStripMenuItem.Checked) ) { for (int i = 0; i < dir.GetLength(0); i++) { bool dir_bool = true; Cell c_jumped = new Cell(); bool jump_begin = false; while (dir_bool) { if (c.x + dir[i, 0] > 0 && c.x + dir[i, 0] < 9 && c.y + dir[i, 1] > 0 && c.y + dir[i, 1] < 9) { Cell c_ = get_cell_for_coordinates(f, c.x + dir[i, 0], c.y + dir[i, 1]); //ход if (c_.color == "empty" && !jump_begin) { temp.add_move_and_auto_decide_where_should_add(new Move(c, c_, level, false, new System.Collections.ArrayList())); } //битье if (jump_begin) { System.Collections.ArrayList jc = new System.Collections.ArrayList(); jc.Add(c_jumped); temp.add_move_and_auto_decide_where_should_add(new Move(c, c_, level, true, jc)); calc_all_cell_moves(temp, c_, level + 1, new Field(f, c_jumped, c_)); dir_bool = false; } //первая пешка для битья if (!jump_begin && c_.color != mine_first_color && c_.color != "empty") { jump_begin = true; c_jumped = c_; } if (dir[i, 0] > 0) { dir[i, 0]++; } else { dir[i, 0]--; } if (dir[i, 1] > 0) { dir[i, 1]++; } else { dir[i, 1]--; } } else { dir_bool = false; } } } } //одиночные ходы и одиночная проверка if ( (английскиеToolStripMenuItem.Checked) || (!c.king && русскиеToolStripMenuItem.Checked) ) { for (int i = 0; i < dir.GetLength(0); i++) { //условие для определения правильной стороны для пешек bool flag_right_direction = ((mine_first_color == "black" && dir[i, 1] < 0) || (mine_first_color == "white" && dir[i, 1] > 0) ); if (c.x + dir[i, 0] > 0 && c.x + dir[i, 0] < 9 && c.y + dir[i, 1] > 0 && c.y + dir[i, 1] < 9 && ((английскиеToolStripMenuItem.Checked && flag_right_direction && !c.king) || (английскиеToolStripMenuItem.Checked && c.king) || русскиеToolStripMenuItem.Checked)) { Cell c_ = get_cell_for_coordinates(f, c.x + dir[i, 0], c.y + dir[i, 1]); dir[i, 0] += dir[i, 0]; dir[i, 1] += dir[i, 1]; //ход if (c_.color == "empty" && !is_additional_jump && flag_right_direction) { temp.add_move_and_auto_decide_where_should_add(new Move(c, c_, level, false, new System.Collections.ArrayList())); } //битье else if (c.x + dir[i, 0] > 0 && c.x + dir[i, 0] < 9 && c.y + dir[i, 1] > 0 && c.y + dir[i, 1] < 9) { Cell c_jump = get_cell_for_coordinates(f, c.x + dir[i, 0], c.y + dir[i, 1]); if (c_jump.color == "empty" && c_.color != mine_first_color && c_.color != "empty") { System.Collections.ArrayList jc = new System.Collections.ArrayList(); jc.Add(c_); temp.add_move_and_auto_decide_where_should_add(new Move(c, c_jump, level, true, jc)); //здесь идет рекурсивная проверка на ходы следующих уровней (двойное+ битье) calc_all_cell_moves(temp, c_jump, level + 1, new Field(f, c_, c_jump)); } } } } } }