/**
* @file Main.cpp
* @autor Коваленко І. В. 515б
* @date 24.03.2023
* @brief Лабораторна робота №4, варіант 11
*
* Використання масивів. Завдання 3
*/
#include <stdio.h>
#include <locale.h>
#include <stdlib.h>
#include <time.h>
#include "Module.h"
//главная функция
int main(void) {
//локализация и гениратор псевдорандомных чисел
setlocale(LC_ALL, "ru");
srand(time(NULL));
//инициализация переменных
int num_cards = 1, num_players = 1;
//создание массивов
const char rank_of_cards[14] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', 't', 'j', 'q', 'k', 'a' };
const char suit_of_cards[4] = { 'c', 's', 'h', 'd' };
int fullhouse_checker[14] = { 0 };
//создание указателей на массивы
int* p_num_cards = &num_cards;
int* p_fullhouse = &fullhouse_checker[0];
//генерация колоды игроков...
printf("Генерация колоды игроков...\n");
//вывод на три игрока
while (num_players <= 3) {
num_cards = 1;
printf("\nКалода игрока №%i: \n", num_players);
//вывод на шесть карт
while (num_cards <= 6) {
printf("%i. ", num_cards);
int i = 0;
do {
i = in_hand_checker(suit_of_cards, rank_of_cards, p_num_cards, p_fullhouse);
} while (i != 1);
}
//инициализация проверки было или не было
bool full_house_dos = false;
bool full_house_tress = false;
//проверка на фулл-хаус
for (int i = 0; i < 14; i++) {
if (fullhouse_checker[i] == 3)
full_house_tress = true;
if (fullhouse_checker[i] == 2)
full_house_dos = true;
}
//вывод фулл-хаус или не фулл-хаус
if (full_house_tress == true && full_house_dos == true)
printf("\tУ игрока №%i в руке фулл-хаус!\n", num_players);
else
printf("\tУ игрока №%i фулл-хаус не обнаружен.\n", num_players);
//обнуление проверки
for (int i = 0; i < 14; i++)
fullhouse_checker[i] = 0;
//следующий игрок
num_players++;
}
}
#define PUBLIC
#define PRIVALE static
#define ERROR 0
#define CORRECT 1
#define NUM_SUITS 4
#define NUM_RANK 13
#define bool int
#define true 1
#define false 0
int in_hand_checker(const char hex_hand_suit[], const char hex_hand_rank[], int* pnc, int* pfh);
#include "Module.h"
#include <stdio.h>
#include <stdlib.h>
//в руке игрока (масть, ранг, номер карты, для заполнение массива)
PUBLIC int in_hand_checker(const char hex_hand_suit[], const char hex_hand_rank[], int* pnc, int* pfh) {
//создание статической руки игроков aka колода
static int in_hand[NUM_SUITS][NUM_RANK] = { 0 };
//наполнение рандомными значениями
int suit = rand() % NUM_SUITS;
int rank = rand() % NUM_RANK;
//проверка на повтор карты
if (!in_hand[suit][rank]) {
in_hand[suit][rank] = 1;
(*pnc)++;
printf(" %c", hex_hand_rank[rank]);
switch (hex_hand_suit[suit]) {
case 'h':
printf("\x03");
break;
case 'd':
printf("\x04");
break;
case 'c':
printf("\x05");
break;
case 's':
printf("\x06");
break;
}
//переход на следующий элемент
(*(pfh + rank))++;
printf("\n");
return CORRECT;
}
//вывод для ошибки
else { return ERROR; }
}