需要帮助解决跳棋跳棋的问题,选手一可以跳,而选手二不能跳 [英] Need help fixing jumping for checkers player one can jump but player twos cant

查看:117
本文介绍了需要帮助解决跳棋跳棋的问题,选手一可以跳,而选手二不能跳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个代码,该代码应使黑色(player2s)的黑色棋子跳上白色,然后越过白色,但它只能跳到棋子上,并且对玩家一个有用.

I have set up a code that should make the black pieces(player2s) jump on the whites then over it but it only jumps onto the piece and jumping worked for player one

	void p1Turn(string name1)
	{	
		int letter=1;
		int irow = 0;
		int frow = 0;
		int icol = 0;
		int fcol = 0;
		int error=0;
		int error1=0;
		while(letter==1)
		{
		letter=1;
		string initial;
		string final;
		irow = 0;
		frow = 0;
		icol = 0;
		fcol = 0;
  		cout << name1 << "'s turn.\n";
		cout << "Input square of piece you want to move (example: A1): ";
		cin >>initial;
		cout << "Now enter square you want to move it to: ";
		cin >> final;
		int bugcounter=0;
				for(int y=0;y<32;y++)
		{
			if(final!=spaces[y])
			{
				error++;
			}
			if(final==spaces[y])
			{
				y=32;
			}
		}
		for(int j=0;j<32;j++)
		{
			if(initial!=spaces[j])
			{
				error1++;
			}
			if(initial==spaces[j])
			{
				j=32;		
			}
		}
		if(error==32 and error1==32)
		{
			cout<<"choose your own piece and somewhere on the board";
		}
		if(error!=32 and error1!=32)
		{
		letter=0;
		switch (initial[0])
		{
			case 'A':
				irow = 0;
				if(final[0]!='B')
				{
				  cout<<"you can only move to B until you become a king\n";
				  bugcounter=1;
				}
				break;
			case 'B':
				irow = 1;
				if(final[0]!='C')
				{
				  cout<<"you can only move to C until you become a king\n";
				  bugcounter=1;
				}
				break;
			case 'C':
				irow = 2;
				if(final[0]!='D')
				{
				  cout<<"you can only move to D until you become a king\n";
				  bugcounter=1;
				}
				break;
			case 'D':
				irow = 3;
				if(final[0]!='E')
				{
				  cout<<"you can only move to E until you become a king\n";
				  bugcounter=1;
				}
				break;
			case 'E':
				irow = 4;
				if(final[0]!='F')
				{
				  cout<<"you can only move to F until you become a king\n";
				  bugcounter=1;
				}
				break;
			case 'F':
				irow = 5;
				if(final[0]!='G')
				{
				  cout<<"you can only move to G until you become a king\n";
				  bugcounter=1;
				}
				break;
			case 'G':
				irow = 6;
				if(final[0]!='H')
				{
				  cout<<"you can only move to H until you become a king\n";
				  bugcounter=1;
				}
				break;
			case 'H':
				irow = 7;
				if(final[0]!='G')
				{
				  cout<<"you can only move to G right now as a king\n";
				  bugcounter=1;
				}
				break;
		}
		switch (initial[1])
		{
			case '1':
				icol = 1;
				if(final[1]!='2')
				{
				  bugcounter=1;
				}
				break;
			case '2':
				icol = 2;
				if(final[1]!='1' or '3')
				{
				  bugcounter=1;
				}
				break;
			case '3':
				icol = 3;
				if(final[1]!='2' or '4')
				{
				  bugcounter=1;
				}
				break;
			case '4':
				icol = 4;
				if(final[1]!='3'or'5')
				{
				  bugcounter=1;
				}
				break;
			case '5':
				icol = 5;
				if(final[1]!='4'or'6')
				{
				  bugcounter=1;
				}
				break;
			case '6':
				icol = 6;
				if(final[1]!='5'or'7')
				{
				  bugcounter=1;
				}
				break;
			case '7':
				icol = 7;
				if(final[1]!='6' or '8')
				{
				  bugcounter=1;
				}
				break;
			case '8':
				icol = 8;
				if(final[1]!='7')
				{
				  bugcounter=1;
				}
				break;
		}
		switch (final[0])
		{
			case 'A':
				frow = 0;
				break;
			case 'B':
				frow = 1;
				break;
			case 'C':
				frow = 2;
				break;
			case 'D':
				frow = 3;
				break;
			case 'E':
				frow = 4;
				break;
			case 'F':
				frow = 5;
				break;
			case 'G':
				frow = 6;
				break;
			case 'H':
				frow = 7;
				break;
		}
		switch (final[1])
		{
			case '1':
				fcol = 1;
				break;
			case '2':
				fcol = 2;
				break;
			case '3':
				fcol = 3;
				break;
			case '4':
				fcol = 4;
				break;
			case '5':
				fcol = 5;
				break;
			case '6':
				fcol = 6;
				break;
			case '7':
				fcol = 7;
				break;
			case '8':
				fcol = 8;
				break;
		}
			if(board[irow][icol]=="⛁")
			{
		switch (initial[0])
		{
			case 'A':
				irow = 0;
				if(final[0]!='B')
				{
				  cout<<"you can only move to B until you become a king\n";
				  bugcounter=1;
				}
				break;
			case 'B':
				irow = 1;
				if(final[0]!='C'or final[0]!='A')
				{
				  cout<<"you can only move to C or A as a king\n";
				  bugcounter=1;
				}
				break;
			case 'C':
				irow = 2;
				if(final[0]!='D'or final[0]!='B')
				{
				  cout<<"you can only move to D or B as a king\n";
				  bugcounter=1;
				}
				break;
			case 'D':
				irow = 3;
				if(final[0]!='E'or final[0]!='C')
				{
				  cout<<"you can only move to E or C as a king\n";
				  bugcounter=1;
				}
				break;
			case 'E':
				irow = 4;
				if(final[0]!='F' or final[0]!='D')
				{
				  cout<<"you can only move to F or D as a king\n";
				  bugcounter=1;
				}
				break;
			case 'F':
				irow = 5;
				if(final[0]!='G'or final[0]!='E')
				{
				  cout<<"you can only move to G or E as a king\n";
				  bugcounter=1;
				}
				break;
			case 'G':
				irow = 6;
				if(final[0]!='H' or final[0]!='F')
				{
				  cout<<"you can only move to H or G as a king\n";
				  bugcounter=1;
				}
				break;
			case 'H':
				irow = 7;
				if(final[0]!='G')
				{
				  cout<<"you can only move to G right now as a king\n";
				  bugcounter=1;
				}
				break;
		}
}
			if(board[irow][icol]!="⛀|")
			{
			  cout<<"that is not a possible movement try again";
			  bugcounter=1;
			}
			if(board[frow][fcol]!="_|")
			{
					if(board[irow][icol]=="⛁|")
					{
						if(icol < fcol and irow < frow)
						{
							if(fcol+1>8)
							{
							cout<<"that is not a possible movement";
							bugcounter=1;
							}
							else
							{
							board[frow][fcol] = "_|";
							frow = frow+1;
							fcol = fcol+1;
							}
						}
						if(icol > fcol and irow < frow)
						{
							if(fcol-1<=0)
							{
							cout<<"that is not a possible movement";
							bugcounter=1;
							}
							else
							{
							board[frow][fcol] = "_|";
							frow = frow+1;
							fcol = fcol-1;
							}
						}
						if(icol < fcol and irow > frow)
						{
							if(fcol+1>8)
							{
							cout<<"that is not a possible movement";
							bugcounter=1;
							}
							else
							{
							board[frow][fcol] = "_|";
							frow = frow-1;
							fcol = fcol+1;
							}
						}
						if(icol > fcol and irow > frow)
						{
							if(fcol-1<=0)
							{
							cout<<"that is not a possible movement";
							bugcounter=1;
							}
							else
							{
							board[frow][fcol] = "_|";
							frow = frow-1;
							fcol = fcol-1;
							}
						}
					}
				if(board[frow][fcol]=="⛂|")
				{
					if(icol < fcol)
					{
						if(fcol+1 >=8)
						{
							cout<<"that is not a possible movement";
							bugcounter=1;
						}
						else
						{
						board[frow][fcol]="_|";
						frow=frow+1;
						fcol=fcol+1;
						}
					}
					if(icol > fcol)
					{
						if(fcol-1 <=0)
						{
							cout<<"that is not a possible movement";
							bugcounter=1;
						}
						else
						{
						board[frow][fcol]="_|";
						frow=frow+1;
						fcol=fcol-1;
						}
					}
				}
			}
			if(board[irow][icol]=="⛀|" and board[frow][fcol]=="_|")
			{
				bugcounter=0;
			}
			if(bugcounter==1)
			{
			  letter=1;
			}
			if(bugcounter==0)
			{
			  letter=0;
			}
		}//end of if statement
		}//end of whileloop
		if(error!=32 and error1!=32)
		{
		board[frow][fcol] = board[irow][icol];
		board[irow][icol] = board[0][2];
		if(board[7][2] == "⛀|"or board[7][4] == "⛀|"or board[7][6] == "⛀|"or board[7][8] == "⛀|")
		{
			board[frow][fcol] = "⛁|";
		}
		}//end of if statement
	}//end of p1Turn

	void p2Turn(string name2)
	{
		int letter=1;
		int irow = 0;
		int frow = 0;
		int icol = 0;
		int fcol = 0;
		int error=0;
		int error1=0;
		int bugcounter=0;
		while(letter==1)
		{
		letter=0;
		string initial;
		string final;
		irow = 0;
		frow = 0;
		icol = 0;
		fcol = 0;
  		cout << name2 << "'s turn.\n";
		cout << "Input square of piece you want to move (example: A1): ";
		cin >>initial;
		cout << "Now enter square you want to move it to: ";
		cin >> final;
				for(int y=0;y<32;y++)
		{
			if(final!=spaces[y])
			{
				error++;
			}
			if(final==spaces[y])
			{
				y=32;
			}
		}
		for(int j=0;j<32;j++)
		{
			if(initial!=spaces[j])
			{
				error1++;
			}
			if(initial==spaces[j])
			{
				j=32;		
			}
		}
		if(error==32 and error1==32)
		{
			cout<<"choose your own piece and somewhere on the board";
		}
		if(error!=32 and error1!=32)
		{
		letter=0;
		switch (initial[0])
		{
			case 'A':
				irow = 0;
				if(final[0]!='B')
				{
				  cout<<"you can only move to B as a king\n";
				  bugcounter=1;
				}
				break;
			case 'B':
				irow = 1;
				if(final[0]!='A')
				{
				  cout<<"you can only move to A until you become a king\n";
				  bugcounter=1;
				}
				break;
			case 'C':
				irow = 2;
				if(final[0]!='B')
				{
				  cout<<"you can only move to B until you become a king\n";
				  bugcounter=1;
				}
				break;
			case 'D':
				irow = 3;
				if(final[0]!='C')
				{
				  cout<<"you can only move to C until you become a king\n";
				  bugcounter=1;
				}
				break;
			case 'E':
				irow = 4;
				if(final[0]!='D')
				{
				  cout<<"you can only move to D until you become a king\n";
				  bugcounter=1;
				}
				break;
			case 'F':
				irow = 5;
				if(final[0]!='E')
				{
				  cout<<"you can only move to E until you become a king\n";
				  bugcounter=1;
				}
				break;
			case 'G':
				irow = 6;
				if(final[0]!='F')
				{
				  cout<<"you can only move to F until you become a king\n";
				  bugcounter=1;
				}
				break;
			case 'H':
				irow = 7;
				if(final[0]!='G')
				{
				  cout<<"you can only move to G until you become a king\n";
				  bugcounter=1;
				}
				break;
		}
		switch (initial[1])
		{
			case '1':
				icol = 1;
				if(final[1]!='2')
				{
				  bugcounter=1;
				}
				break;
			case '2':
				icol = 2;
				if(final[1]!='1' or '3')
				{
				  bugcounter=1;
				}
				break;
			case '3':
				icol = 3;
				if(final[1]!='2' or '4')
				{
				  bugcounter=1;
				}
				break;
			case '4':
				icol = 4;
				if(final[1]!='3'or'5')
				{
				  bugcounter=1;
				}
				break;
			case '5':
				icol = 5;
				if(final[1]!='4'or'6')
				{
				  bugcounter=1;
				}
				break;
			case '6':
				icol = 6;
				if(final[1]!='5'or'7')
				{
				  bugcounter=1;
				}
				break;
			case '7':
				icol = 7;
				if(final[1]!='6' or '8')
				{
				  bugcounter=1;
				}
				break;
			case '8':
				icol = 8;
				if(final[1]!='7')
				{
				  bugcounter=1;
				}
				break;
		}
		switch (final[0])
		{
			case 'A':
				frow = 0;
				break;
			case 'B':
				frow = 1;
				break;
			case 'C':
				frow = 2;
				break;
			case 'D':
				frow = 3;
				break;
			case 'E':
				frow = 4;
				break;
			case 'F':
				frow = 5;
				break;
			case 'G':
				frow = 6;
				break;
			case 'H':
				frow = 7;
				break;
		}
		switch (final[1])
		{
			case '1':
				fcol = 1;
				break;
			case '2':
				fcol = 2;
				break;
			case '3':
				fcol = 3;
				break;
			case '4':
				fcol = 4;
				break;
			case '5':
				fcol = 5;
				break;
			case '6':
				fcol = 6;
				break;
			case '7':
				fcol = 7;
				break;
			case '8':
				fcol = 8;
				break;
		}
		}
			if(board[irow][icol]=="⛃|")
			{
		switch (initial[0])
		{
			case 'A':
				irow = 0;
				if(final[0]!='B')
				{
				  cout<<"you can only move to B as a king\n";
				  bugcounter=1;
				}
				break;
			case 'B':
				irow = 1;
				if(final[0]!='C'or final[0]!='A')
				{
				  cout<<"you can only move to C or A as a king\n";
				  bugcounter=1;
				}
				break;
			case 'C':
				irow = 2;
				if(final[0]!='D'or final[0]!='B')
				{
				  cout<<"you can only move to D or B as a king\n";
				  bugcounter=1;
				}
				break;
			case 'D':
				irow = 3;
				if(final[0]!='E'or final[0]!='C')
				{
				  cout<<"you can only move to E or C as a king\n";
				  bugcounter=1;
				}
				break;
			case 'E':
				irow = 4;
				if(final[0]!='F' or final[0]!='D')
				{
				  cout<<"you can only move to F or D as a king\n";
				  bugcounter=1;
				}
				break;
			case 'F':
				irow = 5;
				if(final[0]!='G'or final[0]!='E')
				{
				  cout<<"you can only move to G or E as a king\n";
				  bugcounter=1;
				}
				break;
			case 'G':
				irow = 6;
				if(final[0]!='H' or final[0]!='F')
				{
				  cout<<"you can only move to H or G as a king\n";
				  bugcounter=1;
				}
				break;
			case 'H':
				irow = 7;
				if(final[0]!='G')
				{
				  cout<<"you can only move to G right now as a king\n";
				  bugcounter=1;
				}
				break;
		}
					if(board[irow][icol]=="⛃|")
					{
						if(icol < fcol and irow < frow)
						{
							if(fcol+1>8)
							{
							cout<<"that is not a possible movement";
							bugcounter=1;
							}
							else
							{
							board[frow][fcol] = "_|";
							frow = frow+1;
							fcol = fcol+1;
							}
						}
						if(icol > fcol and irow < frow)
						{
							if(fcol-1<=0)
							{
							cout<<"that is not a possible movement";
							bugcounter=1;
							}
							else
							{
							board[frow][fcol] = "_|";
							frow = frow+1;
							fcol = fcol-1;
							}
						}
						if(icol < fcol and irow > frow)
						{
							if(fcol+1>8)
							{
							cout<<"that is not a possible movement";
							bugcounter=1;
							}
							else
							{
							board[frow][fcol] = "_|";
							frow = frow-1;
							fcol = fcol+1;
							}
						}
						if(icol > fcol and irow > frow)
						{
							if(fcol-1<=0)
							{
							cout<<"that is not a possible movement";
							bugcounter=1;
							}
							else
							{
							board[frow][fcol] = "_|";
							frow = frow-1;
							fcol = fcol-1;
							}
						}
					}
			if(board[irow][icol]!="⛂|")
			{
			  cout<<"that is not a possible movement try again";
			  bugcounter=1;
			}
			if(board[frow][fcol]!="_|")
			{
					if(board[irow][icol]=="⛃|")
					{
						if(icol < fcol and irow < frow)
						{
							if(fcol+1>8)
							{
							cout<<"that is not a possible movement";
							bugcounter=1;
							}
							else
							{
							board[frow][fcol] = "_|";
							frow = frow+1;
							fcol = fcol+1;
							}
						}
						if(icol > fcol and irow < frow)
						{
							if(fcol-1<=0)
							{
							cout<<"that is not a possible movement";
							bugcounter=1;
							}
							else
							{
							board[frow][fcol] = "_|";
							frow = frow+1;
							fcol = fcol-1;
							}
						}
						if(icol < fcol and irow < frow)
						{
							if(fcol+1>=8)
							{
							cout<<"that is not a possible movement";
							bugcounter=1;
							}
							else
							{
							board[frow][fcol] = "_|";
							frow = frow-1;
							fcol = fcol+1;
							}
						}
						if(icol > fcol and irow > frow)
						{
							if(fcol-1<=0)
							{
							cout<<"that is not a possible movement";
							bugcounter=1;
							}
							else
							{
							board[frow][fcol] = "_|";
							frow = frow-1;
							fcol = fcol-1;
							}
						}
					}
				if(board[frow][fcol]=="⛀|")
				{
					if(icol < fcol)
					{
						if(fcol+1 <=8)
						{
							cout<<"that is not a possible movement";
							bugcounter=1;
						}
						else
						{
						bugcounter=0;
						board[frow][fcol]="_|";
						frow=frow-1;
						fcol=fcol+1;
						}
					}
					if(icol > fcol)
					{
						if(fcol-1 <=0)
						{
							cout<<"that is not a possible movement";
							bugcounter=1;
						}
						else
						{
						bugcounter=0;
						board[frow][fcol]="_|";
						frow=frow-1;
						fcol=fcol-1;
						}
					}
				}
			}
			if(board[irow][icol]=="⛂|" and board[frow][fcol]=="_|")
			{
				bugcounter=0;
			}
			if(bugcounter==1)
			{
			  letter=1;
			}
			if(bugcounter==0)
			{
			  letter=0;
			}
		}
		}
		if(error!=32 and error1!=32)
		{
		board[frow][fcol] = board[irow][icol];
		board[irow][icol] = board[0][2];
		if(board[0][1] == "⛂|"or board[0][3] == "⛂|"or board[0][5] == "⛂|"or board[0][7] == "⛂|")
		{
			board[frow][fcol] = "⛃|";
		}
		}
	}//end of p2Turn


I have only sent a script of it and the first function fully works the second one I have been trying to fix for over a week plz help me


I have only sent a script of it and the first function fully works the second one I have been trying to fix for over a week plz help me

推荐答案

The only way I can help you is to give you some practical advice: stop doing what you are doing: you are not yet ready for such problems. Instead, learn some programming. You code is all wrong from the very beginning so fixing and even reading it would be a total waste of time. If has almost nothing to do with programming.

To illustrate this, let''s look at:
The only way I can help you is to give you some practical advice: stop doing what you are doing: you are not yet ready for such problems. Instead, learn some programming. You code is all wrong from the very beginning so fixing and even reading it would be a total waste of time. If has almost nothing to do with programming.

To illustrate this, let''s look at:
switch (initial[1])
        {
            case '1':
                icol = 1;
                if(final[1]!='2')
                {
                  bugcounter=1;
                }
                break;
             // 2, 3... 8
        }


This it not bad programming, this is not programming at all. Programming is all about re-use and abstraction.应该是这样的


This it not bad programming, this is not programming at all. Programming is all about re-use and abstraction. It should be something like

icol = initial[1];
if (final[icol] != icol + 1) //...


Same thing about case ''A''… case ''H''. You should not use letters at all, you should use a matrix 8x8; the letters should come only when you need to draw a board on screen or record the party. And the letters could be calculated out of numbers in one line, without any switch statements. The identifier bugcounter along tells the tail.
I don''t say that the "fixed" code makes sense, but the original code should not exist at all. If you try to continue with such understanding of programming and even with such level of elementary logic, you will get sunken even in much simpler problems. Right now your attempts to make working code looks like "fixing" a TV set by kicking it until it starts showing a picture.

严重地. Going forward would not make any sense at all; it''s wasting too much time in vain. You need to go back, try to learn programming from the very basics, starting with simple exercises. You would need a good book on C++ and general programming technique, do many of the exercises, read it from the very beginning to the very end. This can be orders of magnitude more effective.

—SA


Same thing about case ''A''… case ''H''. You should not use letters at all, you should use a matrix 8x8; the letters should come only when you need to draw a board on screen or record the party. And the letters could be calculated out of numbers in one line, without any switch statements. The identifier bugcounter along tells the tail.
I don''t say that the "fixed" code makes sense, but the original code should not exist at all. If you try to continue with such understanding of programming and even with such level of elementary logic, you will get sunken even in much simpler problems. Right now your attempts to make working code looks like "fixing" a TV set by kicking it until it starts showing a picture.

Seriously. Going forward would not make any sense at all; it''s wasting too much time in vain. You need to go back, try to learn programming from the very basics, starting with simple exercises. You would need a good book on C++ and general programming technique, do many of the exercises, read it from the very beginning to the very end. This can be orders of magnitude more effective.

—SA


这篇关于需要帮助解决跳棋跳棋的问题,选手一可以跳,而选手二不能跳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆