#include<iostream>
#include<array>
#include<string>
#include<random>
#include<ctime>
using player_t = std::array<unsigned, 2>;
using pair_t = std::pair<unsigned, unsigned>;
using snake_t = std::array<pair_t, 10>;
using ladder_t = std::array<std::pair<unsigned, unsigned>, 9>;
const std::string player (const bool human)
{
return std::string {human ? "You" : "I"};
}
int main()
{
std::default_random_engine generator ((unsigned) time (0));
std::uniform_int_distribution<unsigned> distribution (1, 6);
player_t players = {0,0};
const snake_t snakes = {pair_t {98,78}, {95,75}, {93,73}, {87,24}, {64,60}, {62,19}, {56,53}, {49,11}, {47,26}, {16,6}};
const ladder_t ladders = {pair_t {1,38}, {4,14}, {9,31}, {21,42}, {28,84}, {36,44}, {51,67}, {71,91}, {80,100}};
std::cout << "Snakes and Ladders\n";
std::cout << "==================\n\n";
std::cout << "First to land exactly on square 100 wins.\n";
bool human = (distribution (generator) % 2)==0 ? true : false;
std::cout << player (human) << " will go first.\n\n";
for (;;human=!human)
{
std::cout << (human ? "Your" : "My") << " turn:\n";
unsigned dice = distribution (generator);
std::cout << '\t' << player (human) << " rolled a " << dice << ".\n";
unsigned& pos = players [human?0:1];
if (pos+dice>100)
{
std::cout << '\t' << player (human) << " cannot move";
goto next_player;
}
pos+=dice;
std::cout << '\t' << player (human) << " landed on square " << pos;
for (auto snake : snakes)
{
if (snake.first==pos)
{
pos = snake.second;
std::cout << " with a snake; return to square " << pos;
goto next_player;
}
}
for (auto ladder : ladders)
{
if (ladder.first==pos)
{
pos = ladder.second;
std::cout << " with a ladder; climb to square " << pos;
goto next_player;
}
}
next_player:
std::cout << ".\n\n";
if (pos==100)
{
std::cout << player (human) << " won!\n";
break;
}
}
}
The A Plus Program is an initiative, not a test. So no, there is no answer book.
Every C plus plus program that is a main program must have the function 'main'.
how to write a program that counts automorphic number from 1 to 999
d a tool for analysing c plus plus program
Text editor.
A C++ game project program could either be a game written in C++ or a C++ library that helps you develop a game.
yes! why not! this c program is used in ATM servicesand also in games.
There is no preset limit on the size of an else-if ladder in C++. It depends on compiler design and available memory.
Exit the program and relaunch it.
Yes, you can program games with C++.
The A Plus Program is an initiative, not a test. So no, there is no answer book.
worm and snake.
Because you aren't careful enough.
Every C plus plus program that is a main program must have the function 'main'.
how to write a program that counts automorphic number from 1 to 999
d a tool for analysing c plus plus program
in the gghgouk i