Инструкция пользователя
При запуске игры открывается меню (рис. 3).
Рисунок
3 — меню игры
Игрок может прочесть инструкцию с правилами игры и управлением (рис. 4).
Рисунок
4 - инструкция
Так же игрок может начать играть против ИИ или бой 1 на 1 (рис. 5). После окончании игры пользователя перебросит обратно в меню с надписью какая из сторон выиграла.
Рисунок
5 — игровое поле и интерфейс
Инструкция программиста
Классы:
Класс checkers – данный класс предоставляет методы для оперирования объектом шашка
-CreateCheckers - создание шашек и их расстановка на поле
-DeleteView - удалить маршруты
Класс Board — данный класс предоставляет методы для оперирования объектом шахматная доска
-CreateBoard - создание шахматной доски
-ClearBoard - чистка доски
-placement_of_checkers - расстановка шашек
-CheckFullSquare - проверка места шашки
Класс Game – данный класс содержит главную логику для работы игры
-Work — создание доски
-ShowMenu - показать меню
-OneVSOne— бой один на один
-fightAi— бой с ИИ
-Interface — интерфейс игры
-Manual - инструкция
-Menu - меню
-CheckRoutesAI - проверка маршрутов шашки ИИ
-move_AI -ход AI
-StartMiniMaxFunction - старт минимакс
-minimax — рекурсивная функция минимакс
-EvaluationFunction - оценочная функция
-OutsideOfHome - начисление очков обеим сторонам за нахождение шашек вне своего дома
-CloseToHome - начисление очков обеим сторонам за нахождение шашек у дома противника
-InHome - начисление очков обеим сторонам за нахождение шашки в доме противника
-CheckRoute - выбор шашки для хода
-CheckMove - проверка хода
-ViewRoute - отображение всех возможных ходов
-Move - ход
-Timer - таймер
-CheckWin - проверка победы
Стркутуры:
-struct move — структура хода для шашки ИИ
Листинг кода
Файл cpp:
#include <SFML/Graphics.hpp>
#include "class_game.h"
using namespace sf;
int main()
{
RenderWindow window(VideoMode(1400, 800), "Game"); // Объект окно
Game game;
game.ShowMenu(window, '0');
return 0;
}
Файл class_checkers.h:
#pragma once
#include <SFML/Graphics.hpp>
#include "class_checkers.h"
#include "boards.h"
using namespace sf;
class Checkers
{
public:
void CreateCheckers(RenderWindow& window) // Создание шашек и их расстановка на поле
{
CircleShape circle(25);
for (int i = 0; i < 8; ++i)
{
for (int j = 0; j < 8; ++j)
{
if (board_char[i][j] != '0')
{
circle.setPosition(j * 100 + 40 / 2, i * 100 + 40 / 2);
circle.setOutlineThickness(0);
circle.setOutlineColor(Color::Transparent);
if (board_char[i][j] == '1')
{
circle.setFillColor(Color(150, 50, 250));
}
if (board_char[i][j] == '2')
{
circle.setFillColor(Color(250, 100, 150));
}
if (board_char[i][j] == '3')
{
circle.setFillColor(Color(250, 250, 250));
circle.setOutlineThickness(5);
circle.setOutlineColor(Color(250, 150, 100));
}
window.draw(circle);
}
}
}
}
void DeleteView() // Удалить маршруты
{
for (int i = 0; i < 8; ++i)
{
for (int j = 0; j < 8; ++j)
{
if (board_char[i][j] == '3')
{
board_char[i][j] = '0';
}
}
}
}
};
Файл class_board.h
#pragma once
#include <SFML/Graphics.hpp>
#include "class_checkers.h"
#include "boards.h"
using namespace sf;
class Board
{
public:
void CreateBoard(RenderWindow& window) // Создание шахматной доски
{
RectangleShape square;
square.setSize(Vector2f(100, 100));
for (int i = 0; i < 8; ++i)
{
for (int j = 0; j < 8; ++j)
{
square.setPosition(i * 100, j * 100);
if (board_int[i][j] == 1)
{
square.setFillColor(Color::White);
}
else
{
square.setFillColor(Color::Black);
}
window.draw(square);
}
}
placement_of_checkers(window);
}
void ClearBoard() // Чистка доски
{
chekers.DeleteView();
}
void placement_of_checkers(RenderWindow& window) // Расстановка шашек
{
chekers.CreateCheckers(window);
}
void CheckFullSquare(int y, int x, int original_y, int original_x, char checkers) // Проверка место шашки
{
if (board_char[y][x] == '0')
{
board_char[y][x] = '3';
}
else if (board_char[y][x] == '1' && checkers == '2')
{
if (board_char[y][x + 1] == '0' && original_y == y && original_x == x - 1)
{
board_char[y][x + 1] = '3';
}
else if (board_char[y][x - 1] == '0' && original_y == y && original_x == x + 1)
{
board_char[y][x - 1] = '3';
}
else if (board_char[y + 1][x] == '0' && original_y == y - 1 && original_x == x)
{
board_char[y + 1][x] = '3';
}
else if (board_char[y - 1][x] == '0' && original_y == y + 1 && original_x == x)
{
board_char[y - 1][x] = '3';
}
}
else if (board_char[y][x] == '2' && checkers == '1')
{
if (board_char[y][x + 1] == '0' && original_y == y && original_x == x - 1)
{
board_char[y][x + 1] = '3';
}
else if (board_char[y][x - 1] == '0' && original_y == y && original_x == x + 1)
{
board_char[y][x - 1] = '3';
}
else if (board_char[y + 1][x] == '0' && original_y == y - 1 && original_x == x)
{
board_char[y + 1][x] = '3';
}
else if (board_char[y - 1][x] == '0' && original_y == y + 1 && original_x == x)
{
board_char[y - 1][x] = '3';
}
}
}
private:
Checkers chekers;
};
Файл class_game.h:
#pragma once
#include <SFML/Graphics.hpp>
#include "class_board.h"
#include "boards.h"
#include <iostream>
using namespace sf;
class Game
{
public:
Game() // Констркутор класса Game
{
isManual = true;
isMenu = true;
move_count_white = 0;
move_count_black = 0;
move_count_AI = 0;
queue = 0;
menu_num = 0;
manual_num = 0;
texture_background.loadFromFile("C:/Users/rassu/source/repos/CursWork/Images/Border.png);
font.loadFromFile("C:/Users/rassu/source/repos/CursWork/Text/ofont.ru_Retro Gaming.ttf");
sprite_background.setTexture(texture_background);
}
void Work(RenderWindow& window) // Работаем
{
board.CreateBoard(window);
}
void ShowMenu(RenderWindow& window, char symbol) // Показать меню
{
Menu(window, symbol);
}
void OneVSOne(RenderWindow& window) // Бой 1 на 1
{
Clock clock;
while (window.isOpen())
{
Event event;
window.clear();
while (window.pollEvent(event))
{
if (event.type == Event::Closed)
window.close();
if (event.type == Event::KeyPressed)
{
if (event.key.code == Keyboard::Escape)
{
ShowMenu(window, '0');
}
}
}
Work(window);
Interface(window, this->queue, clock);
if (queue % 2 == 0)
{
if (event.type == Event::MouseButtonPressed)
{
if (event.mouseButton.button == Mouse::Left)
{
CheckRoute(event, window, '2');
}
if (event.mouseButton.button == Mouse::Right)
{
CheckMove(event, window, queue, '2');
}
}
}
else
{
if (event.type == Event::MouseButtonPressed)
{
if (event.mouseButton.button == Mouse::Left)
{
CheckRoute(event, window, '1');
}
if (event.mouseButton.button == Mouse::Right)
{
CheckMove(event, window, queue, '1');
}
}
}
window.display();
}
}
void fightAi(RenderWindow& window) // Бой с ИИ
{
Clock clock;
while (window.isOpen())
{
Event event;
window.clear();
while (window.pollEvent(event))
{
if (event.type == Event::Closed)
window.close();
if (event.type == Event::KeyPressed)
{
if (event.key.code == Keyboard::Escape)
{
ShowMenu(window, '0');
}
}
}
Work(window);
Interface(window, this->queue, clock);
if (queue % 2 == 0)
{
if (event.type == Event::MouseButtonPressed)
{
if (event.mouseButton.button == Mouse::Left)
{
CheckRoute(event, window, '2');
}
if (event.mouseButton.button == Mouse::Right)
{
CheckMove(event, window, queue, '2');
}
}
}
else
{
StartMiniMaxFunction();
}
window.display();
}
}
private:
int first_y;
int first_x;
int queue;
int seconds;
int menu_num;
int manual_num;
int move_count_white;
int move_count_black;
int move_count_AI;
bool isMenu;
bool isManual;
std::vector <Checkers> vector_checkers_AI;
Font font;
Board board;
Texture texture_background;
Sprite sprite_background;
RectangleShape square_exit;
RectangleShape square_one_vs_one;
RectangleShape square_fight_AI;
RectangleShape square_manual;
RectangleShape square_back;
Text text_time;
Text text_queue;
Text text_evaluation;
Text text_exit;
Text text_one_vs_one;
Text text_fight_AI;
Text text_manual;
Text text_win_black;
Text text_win_white;
Text text_main_manual;
Text text_back;
Text text_move_count;
Text text_info;
// Интерфейс //
void Interface(RenderWindow& window, int queue, Clock clock) // Интерфейс игры
{
int result = 0;
text_time.setFont(font);
text_queue.setFont(font);
text_evaluation.setFont(font);
text_move_count.setFont(font);
text_info.setFont(font);
text_move_count.setString(L"Общее количество ходов: " + std::to_string(move_count_black + move_count_white));
text_info.setString(L"ESC-выход");
if (queue % 2 == 0)
{
text_queue.setString(L"Ход белых шашек");
}
else
{
text_queue.setString(L"Ход черных шашек");
}
text_time.setString(L"Прошло времени: " + Timer(clock));
result = EvaluationFunction(board_char);
if (result < 0)
{
text_evaluation.setString(L"Выигрышна ситуация черных");
}
else if (result > 0)
{
text_evaluation.setString(L"Выигрышна ситуация белых");
}
else
{
text_evaluation.setString(L"Выигрышная ситуация неопределена");
}
text_info.setCharacterSize(24);
text_move_count.setCharacterSize(24);
text_time.setCharacterSize(24);
text_queue.setCharacterSize(24);
text_evaluation.setCharacterSize(24);
text_info.setFillColor(Color::White);
text_move_count.setFillColor(Color::White);
text_time.setFillColor(Color::White);
text_queue.setFillColor(Color::White);
text_evaluation.setFillColor(Color::White);
text_time.setPosition(805, 25);
text_queue.setPosition(805, 75);
text_evaluation.setPosition(805, 125);
text_move_count.setPosition(805, 175);
text_info.setPosition(805, 225);
window.draw(text_info);
window.draw(text_time);
window.draw(text_queue);
window.draw(text_evaluation);
window.draw(text_move_count);
}
void Manual(RenderWindow& window) // Инструкция
{
while (isManual)
{
window.clear(Color::Black);
text_main_manual.setFont(font);
text_back.setFont(font);
text_main_manual.setString(L"ЛКМ - выбрать шашку\nПКМ - сделать ход\nESC - выйти в меню\n\nПравила окончания игры:\n-Один из игроков переместил все свои шашки в дом соперника.\n Этот игрок выиграл игру.\n-Один из игроков всё ещё имеет несколько своих шашек в своём доме и при этом\n сделал больше чем 60 ходов. Этот игрок проигрывает игру.\n-Игрок также проигрывает игру,\n если он поставил одну из своих шашек обратно в свой дом после 60 - го хода.\n-Игрок также проигрывает\n если после 100 хода количество его шашек вне дома больше чем у соперника.");
text_back.setString(L"Назад");
square_back.setSize(Vector2f(250, 50));
text_main_manual.setCharacterSize(25);
text_back.setCharacterSize(35);
square_back.setFillColor(Color::White);
text_main_manual.setFillColor(Color::White);
text_back.setFillColor(Color::Black);
square_back.setPosition(0, 750);
text_main_manual.setPosition(25, 100);
text_back.setPosition(50, 750);
if (IntRect(0, 750, 300, 50).contains(Mouse::getPosition(window))) { square_back.setFillColor(Color::Magenta); manual_num = 1; }
if (Mouse::isButtonPressed(Mouse::Left))
{
if (manual_num == 1) { isManual = false; manual_num = 0; ShowMenu(window, '0'); }
}
window.draw(square_back);
window.draw(text_main_manual);
window.draw(text_back);
window.display();
}
}
void Menu(RenderWindow& window, char symbol) // Меню
{
while (isMenu)
{
text_exit.setFont(font);
text_one_vs_one.setFont(font);
text_fight_AI.setFont(font);
text_manual.setFont(font);
text_exit.setString(L"Выход");
text_one_vs_one.setString(L"1 на 1");
text_fight_AI.setString(L"Бой с ИИ");
text_manual.setString(L"Инструкция");
square_exit.setSize(Vector2f(275, 50));
square_one_vs_one.setSize(Vector2f(275, 50));
square_fight_AI.setSize(Vector2f(275, 50));
square_manual.setSize(Vector2f(275, 50));
text_exit.setCharacterSize(35);
text_one_vs_one.setCharacterSize(35);
text_fight_AI.setCharacterSize(35);
text_manual.setCharacterSize(35);
square_exit.setFillColor(Color::White);
square_one_vs_one.setFillColor(Color::White);
square_fight_AI.setFillColor(Color::White);
square_manual.setFillColor(Color::White);
text_exit.setFillColor(Color::Black);
text_one_vs_one.setFillColor(Color::Black);
text_fight_AI.setFillColor(Color::Black);
text_manual.setFillColor(Color::Black);
square_exit.setPosition(1000, 525);
square_one_vs_one.setPosition(1000, 425);
square_fight_AI.setPosition(1000, 325);
square_manual.setPosition(1000, 225);
text_exit.setPosition(1060, 520);
text_one_vs_one.setPosition(1070, 420);
text_fight_AI.setPosition(1040, 320);
text_manual.setPosition(1000, 220);
sprite_background.setPosition(0, 0);
if (IntRect(1000, 525, 300, 50).contains(Mouse::getPosition(window))) { square_exit.setFillColor(Color::Magenta); menu_num = 1; }
if (IntRect(1000, 425, 300, 50).contains(Mouse::getPosition(window))) { square_one_vs_one.setFillColor(Color::Magenta); menu_num = 2; }
if (IntRect(1000, 325, 300, 50).contains(Mouse::getPosition(window))) { square_fight_AI.setFillColor(Color::Magenta); menu_num = 3; }
if (IntRect(1000, 225, 300, 50).contains(Mouse::getPosition(window))) { square_manual.setFillColor(Color::Magenta); menu_num = 4; }
if (Mouse::isButtonPressed(Mouse::Left))
{
if (menu_num == 4) { isManual = true; menu_num = 0; Manual(window); }
if (menu_num == 3) { fightAi(window); }
if (menu_num == 2) { OneVSOne(window); }
if (menu_num == 1) { window.close(); isMenu = false; }
}
window.draw(sprite_background);
window.draw(square_exit);
window.draw(square_one_vs_one);
window.draw(square_fight_AI);
window.draw(square_manual);
if (symbol == '2')
{
text_win_white.setFont(font);
text_win_white.setString(L"Победа белых");
text_win_white.setCharacterSize(35);
text_win_white.setFillColor(Color::White);
text_win_white.setPosition(1000, 120);
window.draw(text_win_white);
}
else if (symbol == '1')
{
text_win_black.setFont(font);
text_win_black.setString("Победа черных");
text_win_black.setCharacterSize(35);
text_win_black.setFillColor(Color::White);
text_win_black.setPosition(1000, 120);
window.draw(text_win_black);
}
window.draw(text_exit);
window.draw(text_one_vs_one);
window.draw(text_fight_AI);
window.draw(text_manual);
window.display();
}
}
// AI //
struct move
{
int oldX;
int oldY;
int newX;
int newY;
};
std::vector <int> CheckRoutesAI(int x, int y) // Проверка маршрутов шашки ИИ
{
std::vector <int> returned_move_vec;
if (board_char[x + 1][y] == '0') // низ
{
returned_move_vec.push_back((x + 1) * 10 + y);
}
if (board_char[x + 1][y] == '2' && board_char[x + 2][y] == '0') // низ перепрыгивая шашку
{
returned_move_vec.push_back((x + 2) * 10 + y);
}
if (board_char[x][y - 1] == '0') // лево
{
returned_move_vec.push_back(x * 10 + (y - 1));
}
if (board_char[x][y - 1] == '2' && board_char[x][y - 2] == '0') // лево перепрыгивая шашку
{
returned_move_vec.push_back(x * 10 + (y - 2));
}
if (board_char[x][y + 1] == '0') // право
{
returned_move_vec.push_back(x * 10 + (y + 1));
}
if (board_char[x][y + 1] == '2' && board_char[x][y + 2] == '0') // право перепрыгивая шашку
{
returned_move_vec.push_back(x * 10 + (y + 2));
}
return returned_move_vec;
}
void move_AI(int old_x, int old_y, int new_x, int new_y) // Ход AI
{
board_char[new_x][new_y] = '1';
board_char[old_x][old_y] = '0';
++queue;
++move_count_black;
}
void StartMiniMaxFunction() // Старт минимакс
{
int best = INT_MIN;
move bestMove;
for (int i = 0; i < 8; ++i)
{
for (int j = 0; j < 8; ++j)
{
if (board_char[i][j] == '1')
{
std::vector<int> possibleMoves = CheckRoutesAI(i, j);
for (auto coord : possibleMoves)
{
char curBoard[8][8];
for (int k = 0; k < 8; ++k)
{
for (int t = 0; t < 8; ++t)
{
curBoard[k][t] = board_char[k][t];
}
}
int currentVal = minimax(curBoard, 3, INT_MIN, INT_MAX, false);
if (currentVal > best)
{
best = currentVal;
bestMove.oldX = i;
bestMove.oldY = j;
bestMove.newX = coord / 10;
bestMove.newY = coord % 10;
}
}
}
}
}
move_AI(bestMove.oldX, bestMove.oldY, bestMove.newX, bestMove.newY);
}
int minimax(char field[8][8], int depth, int alpha, int beta, bool maximizingPlayer) // Минимакс
{
if (depth == 0 || CheckWin() != '0')
return EvaluationFunction(field);
if (maximizingPlayer)
{
int max = INT_MIN;
for (int i = 0; i < 8; ++i)
{
for (int j = 0; j < 8; ++j)
{
if (max >= beta)
{
return max;
}
if (field[i][j] == '1')
{
std::vector<int> possibleMoves = CheckRoutesAI(i, j);
for (auto coord : possibleMoves)
{
char curBoard[8][8];
for (int k = 0; k < 8; ++k)
{
for (int t = 0; k < 8; ++k)
{
curBoard[k][t] = board_char[k][t];
}
}
curBoard[i][j] = '0';
curBoard[coord / 10][coord % 10] = '1';
int val = minimax(curBoard, depth - 1, alpha, beta, false);
max = std::max(max, val);
alpha = std::max(alpha, val);
}
}
}
}
return max;
}
else
{
int min = INT_MAX;
for (int i = 0; i < 8; ++i)
{
for (int j = 0; j < 8; ++j)
{
if (min <= alpha)
{
return min;
}
if (field[i][j] == '1')
{
std::vector<int> possibleMoves = CheckRoutesAI(i, j);
for (auto coord : possibleMoves)
{
char curBoard[8][8];
for (int k = 0; k < 8; ++k)
{
for (int t = 0; k < 8; ++k)
{
curBoard[k][t] = board_char[k][t];
}
}
curBoard[i][j] = '0';
curBoard[coord / 10][coord % 10] = '1';
int val = minimax(curBoard, depth - 1, alpha, beta, true);
min = std::min(min, val);
beta = std::min(beta, val);
}
}
}
}
return min;
}
}
// Оценочная функция //
int EvaluationFunction(char board[8][8]) // Оценочная функция
{
return (OutsideOfHome(board, '2') + CloseToHome(board, '2') + InHome(board, '2')) - (OutsideOfHome(board, '1') + CloseToHome(board, '1') + InHome(board, '1'));
}
int OutsideOfHome(char Board[8][8], char Сheckers) // Начисление очков обеим сторонам за нахождение шашек вне своего дома
{
int Count = 0;
if (Сheckers == '2') {
for (int i = 0; i < 8; ++i) {
for (int j = 0; j < 8; ++j) {
if (i < 4 && j < 3) {
if (Board[i][j] == Сheckers) {
Count += 1;
}
}
else if (i == 4) {
if (Board[i][j] == Сheckers) {
Count += 1;
}
}
else if (i > 4 && j > 3) {
if (Board[i][j] == Сheckers) {
Count += 1;
}
}
}
}
}
else
{
for (int i = 0; i < 8; ++i) {
for (int j = 0; j < 8; ++j) {
if (i < 3 && j < 4) {
if (Board[i][j] == Сheckers) {
Count += 1;
}
}
else if (i == 3) {
if (Board[i][j] == Сheckers) {
Count += 1;
}
}
else if (i > 3 && j > 4) {
if (Board[i][j] == Сheckers) {
Count += 1;
}
}
}
}
}
return Count;
}
int CloseToHome(char board[8][8], char checkers) // Начисление очков обеим сторонам за нахождение шашек у дома противника
{
int Count = 0;
if (checkers == '2') {
for (int i = 0; i < 5; ++i) {
for (int j = 3; j < 8; ++j) {
if (i < 3 && j == 3) {
if (board[i][j] == checkers) {
Count += 2;
}
}
else if (i == 4 && j > 2) {
if (board[i][j] == checkers) {
Count += 2;
}
}
}
}
}
else
{
for (int i = 4; i < 8; ++i) {
for (int j = 0; j < 8; ++j) {
if (i == 4 && j < 5) {
if (board[i][j] == checkers) {
Count += 2;
}
}
else if (i > 4 && j == 4) {
if (board[i][j] == checkers) {
Count += 2;
}
}
}
}
}
return Count;
}
int InHome(char board[8][8], char checkers) // Начисление очков обеим сторонам за нахождение шашки в доме противника
{
int Count = 0;
if (checkers == '2') {
for (int i = 0; i < 3; ++i) {
for (int j = 4; j < 8; ++j) {
if (board[i][j] == checkers) {
Count += 3;
}
}
}
}
else
{
for (int i = 5; i < 8; ++i) {
for (int j = 0; j < 4; ++j) {
if (board[i][j] == checkers) {
Count += 3;
}
}
}
}
return Count;
}
// Остальное //
void CheckRoute(Event& event, RenderWindow& window, char checkers) // Выбора шашки для хода
{
if (board_char[event.mouseButton.y / 100][event.mouseButton.x / 100] == checkers)
{
first_y = event.mouseButton.y / 100;
first_x = event.mouseButton.x / 100;
ViewRoute(event.mouseButton.y / 100, event.mouseButton.x / 100, checkers, window, event);
}
}
void CheckMove(Event& event, RenderWindow& window, int& queue, char checkers) // Проверка хода
{
if (board_char[event.mouseButton.y / 100][event.mouseButton.x / 100] == '3')
{
Move(event.mouseButton.y / 100, event.mouseButton.x / 100, first_y, first_x, window);
++queue;
if (checkers == '2')
{
++move_count_white;
}
else
{
++move_count_black;
}
}
}
void ViewRoute(int y, int x, char checkers, RenderWindow& window, Event& event) // Отображение всех возможных ходов
{
board.ClearBoard();
if (checkers == '2')
{
if (y != 0)
{
board.CheckFullSquare(y - 1, x, y, x, checkers);
}
if (x != 0)
{
board.CheckFullSquare(y, x - 1, y, x, checkers);
}
if (x != 7)
{
board.CheckFullSquare(y, x + 1, y, x, checkers);
}
board.CheckFullSquare(y + 1, x, y, x, checkers);
}
else
{
if (y != 7)
{
board.CheckFullSquare(y + 1, x, y, x, checkers);
}
if (x != 7)
{
board.CheckFullSquare(y, x + 1, y, x, checkers);
}
board.CheckFullSquare(y - 1, x, y, x, checkers);
board.CheckFullSquare(y, x - 1, y, x, checkers);
}
}
void Move(int first_y, int first_x, int second_y, int second_x, RenderWindow& window) // Ход
{
char Temp = board_char[second_y][second_x];
board_char[second_y][second_x] = board_char[first_y][first_x];
board_char[first_y][first_x] = Temp;
board.ClearBoard();
char symbol = CheckWin();
if (symbol == '2' || symbol == '1')
{
ShowMenu(window, symbol);
}
}
std::string Timer(Clock& clock) // Таймер
{
Time elapsed_time = clock.getElapsedTime();
seconds = static_cast<int>(elapsed_time.asSeconds());
return std::to_string(seconds);
}
char CheckWin() // Проверка победы
{
int count_black_checkers = 0;
int count_white_checkers = 0;
for (int i = 0; i < 3; ++i)
{
for (int j = 4; j < 8; ++j)
{
if (board_char[i][j] == board_win[i][j])
{
++count_black_checkers;
}
}
}
for (int i = 5; i < 8; ++i)
{
for (int j = 0; j < 4; ++j)
{
if (board_char[i][j] == board_win[i][j])
{
++count_white_checkers;
}
}
}
if (count_white_checkers == 12)
{
return '1';
}
else if (count_black_checkers == 12)
{
return '2';
}
else if (move_count_black == 60 && count_black_checkers == 3)
{
return '2';
}
else if (move_count_white == 60 && count_white_checkers == 3)
{
return '1';
}
else if (move_count_white == 100 && count_white_checkers > count_black_checkers)
{
return '1';
}
else if (move_count_black == 100 && count_white_checkers < count_black_checkers)
{
return '2';
}
return '0';
}
};
Файл boards.h:
#pragma once
// На доске представлены черные и белые шашки
// '1' - черные шашки
// '2' - белые шашки
char board_char[8][8] = {
'0', '0', '0', '0', '1', '1', '1', '1',
'0', '0', '0', '0', '1', '1', '1', '1',
'0', '0', '0', '0', '1', '1', '1', '1',
'0', '0', '0', '0', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0', '0', '0',
'2', '2', '2', '2', '0', '0', '0', '0',
'2', '2', '2', '2', '0', '0', '0', '0',
'2', '2', '2', '2', '0', '0', '0', '0',
};
char board_win[8][8] = {
'0', '0', '0', '0', '2', '2', '2', '2',
'0', '0', '0', '0', '2', '2', '2', '2',
'0', '0', '0', '0', '2', '2', '2', '2',
'0', '0', '0', '0', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0', '0', '0',
'1', '1', '1', '1', '0', '0', '0', '0',
'1', '1', '1', '1', '0', '0', '0', '0',
'1', '1', '1', '1', '0', '0', '0', '0',
};
int board_score_black[8][8] = {
7, 6, 5, 4, 3, 2, 1, 0,
8, 7, 6, 5, 4, 3, 2, 1,
9, 8, 7, 6, 5, 4, 3, 2,
10, 9, 8, 7, 6, 5, 4, 3,
11, 10, 9, 8, 7, 6, 5, 4,
12, 11, 10, 9, 8, 7, 6, 5,
14, 12, 11, 10, 9, 8, 7, 6,
15, 13, 12, 11, 10, 9, 8, 7,
};
int board_int[8][8] = {
{1, 0, 1, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 0, 1, 0, 1}
};
