Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- char **board;
- int borderSize, columnCounts;
- string spaces = " ";
- struct Point{
- int x, y;
- };
- int intLength(int x){
- int n=1;
- while ((x/=10) > 0) n++;
- return n;
- }
- void drawHeader(){
- cout << spaces;
- for(int i=0;i<borderSize;i++){
- cout << char('A'+i) << " ";
- }
- cout << endl;
- }
- void draw(){
- drawHeader();
- for(int i=0;i<borderSize;i++){
- cout << (borderSize-i) << spaces.substr(intLength(borderSize-i));
- for(int j=0;j<borderSize;j++){
- if(board[i][j]==0){
- if((i+j)%2==0)
- cout << " ";
- else
- cout << "██";
- }else if(board[i][j] == 1)
- cout << "<>";
- else
- cout << "@@";
- }
- cout << spaces.substr(intLength(borderSize-i)) << (borderSize-i);
- cout << endl;
- }
- drawHeader();
- }
- Point stringToPoint(string s){
- Point p;
- p.x = s[0]-'A';
- p.y = borderSize-stoi(s.substr(1));
- return p;
- }
- bool move(int player, Point from, Point to){
- if(board[from.y][from.x]==player && abs(from.x-to.x)==1 && abs(from.y-to.y)==1 && board[to.y][to.x]==0){
- board[from.y][from.x] = 0;
- board[to.y][to.x] = player;
- return true;
- }else if(board[from.y][from.x]==player && abs(from.x-to.x)==2 && abs(from.y-to.y)==2 && board[to.y][to.x]==0 && board[(from.y+to.y)/2][(from.x+to.x)/2]!=player){
- board[from.y][from.x] = 0;
- board[(from.y+to.y)/2][(from.x+to.x)/2] = 0;
- board[to.y][to.x] = player;
- return true;
- }
- return false;
- }
- int main()
- {
- cout << "Введите размер доски:" << endl;
- cin >> borderSize;
- borderSize = min(borderSize, 26);
- cout << "Введите количество рядов шашек:" << endl;
- cin >> columnCounts;
- columnCounts = min(columnCounts, borderSize/2);
- string log = "";
- board = new char*[borderSize];
- for(int i=0;i<borderSize;i++){
- board[i] = new char[borderSize];
- for(int j=0;j<borderSize;j++){
- board[i][j] = 0;
- if((i+j)%2 == 1){
- if(i<columnCounts)
- board[i][j] = 1;
- else if((borderSize-i)<=columnCounts)
- board[i][j] = 2;
- }
- }
- }
- int player = 1;
- while(true){
- draw();
- cout << "Ход игрока №" << (player) << endl;
- string from, to;
- cin >> from;
- if(from == "stop"){
- cout << log << endl;
- break;
- }
- cin >> to;
- if(move(player, stringToPoint(from), stringToPoint(to))){
- log += "Игрок ";
- log += (player+'0');
- log += ": " + from + "->" + to + "\n";
- player = (player%2) + 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement