#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define EQUIPMENTLIST_SIZE 5
char gameEquipment[EQUIPMENTLIST_SIZE] = {'f', 'b', 's', 'j', 'm'};
int moveStep(char equipment) {
int step;
switch(equipment) {
case 'f':
step = 1;
break;
case 'b':
step = -1;
break;
case 's':
step = 0;
break;
case 'j':
step = 5;
break;
case 'm':
step = rand() % 11 - 5;
break;
default:
step = 0;
break;
}
return step;
}
void printMoves(int moves[], int size) {
printf("Moves: ");
for (int i = 0; i < size; i++) {
printf("%d ", moves[i]);
}
printf("\n");
}
int main() {
srand(time(0));
int playerA[100] = {0};
int playerB[100] = {0};
int playerA_position = 0;
int playerB_position = 0;
int round = 0;
while (round < 100) {
int diceA = rand() % 6;
int diceB = rand() % 6;
char equipmentA = gameEquipment[diceA];
char equipmentB = gameEquipment[diceB];
int stepA = moveStep(equipmentA);
int stepB = moveStep(equipmentB);
playerA_position += stepA;
playerB_position += stepB;
playerA[round] = playerA_position;
playerB[round] = playerB_position;
if (playerA_position >= 20 || playerB_position >= 20) {
break;
}
round++;
}
printMoves(playerA, round);
printMoves(playerB, round);
if (playerA_position >= 20 && playerB_position >= 20) {
printf("Draw! Both players reached 20 or more steps.\n");
} else if (playerA_position >= 20) {
printf("Player A wins!\n");
} else if (playerB_position >= 20) {
printf("Player B wins!\n");
} else {
int max_position = playerA_position > playerB_position ? playerA_position : playerB_position;
if (playerA_position == playerB_position) {
printf("Draw! Both players reached the same maximum position: %d\n", max_position);
} else if (max_position == playerA_position) {
printf("Player A wins with the maximum position: %d\n", max_position);
} else {
printf("Player B wins with the maximum position: %d\n", max_position);
}
}
return 0;
}