我写了一些代码来移动国王在国际象棋比赛; 你能告诉我国王不动的代码问题在哪里?谢谢.
EDITED2:
public partial class Form1 : Form
{
PictureBox[,] pic = new PictureBox[8, 8];
private void pictureBox34_Click(object sender, EventArgs e)
{
if (pictureBox34.Image == chess9.Properties.Resources.siyahsah2)
{
f();
}
}
public void picarray()
{
pic[0, 0] = pictureBox54;
pic[0, 1] = pictureBox64;
pic[0, 2] = pictureBox48;
pic[0, 3] = pictureBox42;
pic[0, 4] = pictureBox34;
pic[0, 5] = pictureBox26;
pic[0, 6] = pictureBox18;
pic[0, 7] = pictureBox8;
pic[1, 0] = pictureBox1;
pic[1, 1] = pictureBox2;
pic[1, 2] = pictureBox3;
pic[1, …
Run Code Online (Sandbox Code Playgroud) 我在C中的这段代码有问题.
#include <stdio.h>
#include <stdint.h>
typedef uint64_t bboard;
// Accessing a square of the bitboard
int
get (bboard b, int square)
{
return (b & (1ULL << square));
}
void
print_board (bboard b)
{
int i, j, square;
for (i = 7; i >= 0; i--) // rank => top to bottom
{
for (j = 0; j < 8; j++) // file => left to right
printf ("%d ", get (b, j+8*i) ? 1 : 0);
printf ("\n");
} …
Run Code Online (Sandbox Code Playgroud) 我正在写一个国际象棋引擎并获得伪随机移动,我传递一个移动生成函数和一个数组来填充.这是一些代码:
...
else if(pstrcmp(input, (char*)"check", 5)){
int checkIndex = getIndex(input[6], input[7] - 49);
printf("checkindex %i\n", checkIndex);
if(!(checkIndex < 0 || checkIndex > 127)){
//we've received a valid check
struct m mUn[MOVE_BUFF];
gen_psm(checkIndex, mUn);
int i = 0;
while(mUn[i].start != mUn[i].end && i < MOVE_BUFF){
printf("%s\n", GSQ(mUn[i].end));
i++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
...
第一行只是一些输入检查.代码的内容在struct m mUn[MOVE_BUFF]
while循环之间.所以我创建了一个struct m
数组,我创建了一个数组,它包含一些指定特定移动的整数,然后我传递给它,gen_psm
其中需要检查方形的索引和要填充的数组.它为数组填充了位于索引处的片段的有效移动.第一步,精致和花花公子.然后我尝试第二步,我发现数组从第一步开始仍然有数据,即使我已经退出了我声明它的mUn的范围.结构的某些性质是否会保留其数据?我是否需要填充整个事物(当我尝试它时似乎充满了0).如果我需要0填充它,是否有更快的方法(如果我必须0填充它几亿次,这是一个问题)?
我第一次在这里问一个问题,如果我做错了,请纠正我.
我国际象棋的图片:http: //img842.imageshack.us/img842/2695/65744343.png
每次我移动一块它都会滞后大约1秒钟.每件和瓷砖都有一个图像,正好有96个图像.每次我移动一块它都会用黑色清除所有内容,然后更新图形.
在国际象棋的早期阶段,我没有任何图像,而是使用了不同的颜色,只有几件没有明显的滞后,这件作品瞬间移动.
public void updateGraphics(PaintEventArgs e, Graphics g, Bitmap frame)
{
g = Graphics.FromImage(frame);
g.Clear(Color.Black);
colorMap(g);
g.Dispose();
e.Graphics.DrawImageUnscaled(frame, 0, 0);
}
Run Code Online (Sandbox Code Playgroud)
函数colorMap(g)看起来像这样:
private void colorMap(Graphics g)
{
for (int y = 0; y < SomeInts.amount; y++)
{
for (int x = 0; x < SomeInts.amount; x++)
{
//Tiles
Bundle.tile[x, y].colorBody(g, x, y);
//Pieces
player1.colorAll(g);
player2.colorAll(g);
}
}
}
Run Code Online (Sandbox Code Playgroud)
colorAll函数执行每个colorBody(g)函数,如下所示:
public void colorBody(Graphics g)
{
//base.colorBody() does the following: body = new Rectangle(x * SomeInts.size + …
Run Code Online (Sandbox Code Playgroud) 我一直在研究表格,以便我可以使用html中的表格创建一个棋盘.以下是我在网上找到的一些代码:HTML CODE:
<table id="chess_board" cellpadding="0" cellspacing="0">
<tr>
<td id="A8"><a href="#" class="rook black">♜</a></td>
<td id="B8"><a href="#" class="night black">♞</a></td>
<td id="C8"><a href="#" class="bishop black">♝</a></td>
<td id="D8"><a href="#" class="king black">♛</a></td>
<td id="E8"><a href="#" class="queen black">♚</a></td>
<td id="F8"><a href="#" class="bishop black">♝</a></td>
<td id="G8"><a href="#" class="night black">♞</a></td>
<td id="H8"><a href="#" class="rook black">♜</a></td>
</tr>
<tr>
<td id="A7"><a href="#" class="pawn black">♟</a></td>
<td id="B7"><a href="#" class="pawn black">♟</a></td>
<td id="C7"><a href="#" class="pawn black">♟</a></td>
<td id="D7"><a href="#" class="pawn black">♟</a></td>
<td id="E7"><a href="#" class="pawn black">♟</a></td>
<td id="F7"><a href="#" class="pawn black">♟</a></td>
<td …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个国际象棋游戏,并且能够使我的Pawn棋子向前移动一个和两个方格,但我很难防止它在第一次移动后向前移动两个方格.如果有人可以帮助我了解如何实施它的逻辑或想法,我将不胜感激.
这是我的代码:
private boolean isValidPawnMove(int sourceRow, int sourceColumn, int targetRow, int
targetColumn) {
boolean isValid = false;
if(isTargetLocationFree()){
if(sourceColumn == targetColumn){
//same column
if(sourcePiece.getColor() == Piece.YELLOW_COLOR){
//yellow
if(sourceRow + 1 == targetRow ){
//move one up
isValid = true;
}else if(sourceRow + 2 == targetRow ){
isValid = true;
}else{
//not moving one up
isValid = false;
}
}else{
//brown
if(sourceRow - 1 == targetRow){
//move one down
isValid = true;
}else if(sourceRow - 2 == targetRow){
isValid = true; …
Run Code Online (Sandbox Code Playgroud) 我的目标是写一个基本的国际象棋玩AI.它并不需要令人难以置信,但我希望它能够对某些熟悉游戏的人有一定程度的能力.
我有一个名为Piece的特征,它有抽象方法canMakeMove(m:Move,b:Board)和allMovesFrom(p:Position,b:Board).出于显而易见的原因,这些方法对于程序逻辑很重要,并且由具体类King,Queen,Pawn,Rook,Bishop和Knight实现.因此在其他地方,例如在确定特定板是否具有King的代码中,这些方法在类型为抽象类型Piece的值上调用,(piece canMakeMove(...,... ))所以调用的实际方法是在运行时通过动态调度确定的.
我想知道这对于国际象棋AI程序来说是否太昂贵了,而这个程序将不得不多次执行此代码.在网上浏览并阅读有关国际象棋编程的更多内容之后,我发现国际象棋棋盘的最常见表现形式不像我的Vector [Vector [Option [Piece]],而是一个可能使用的int矩阵('bit board')关于板上值的switch语句,以实现我目前依靠动态调度来实现的效果.这会阻止我的AI达到可行的性能水平吗?
我正在尝试创建一个简单的国际象棋程序,我在实现典当促销时遇到了一个小问题.我有一个抽象类和6个类(King,Queen,Rook,Knight,Bishop和Pawn)扩展它.因此,当一个棋子到达棋盘的另一端时,我希望他改变让我们说皇后.
最简单的方法是做这样的事情:
Public class Pawn extends Piece {
...
@Override
public void move(int toCol, int toRow) {
this.col = toCol; this.row = toRow;
if (toRow == endRow)
this = (Queen)this
}
}
Run Code Online (Sandbox Code Playgroud)
这显然是不可能的,因为人们根本无法分配给它.
所以我需要检测促销并从外部投射.但由于某些原因,我存储了两次配件.作为一个2D阵列的片断,但也作为每个玩家的2个片段列表.这意味着我需要在列表中找到pawn并将其删除,然后添加具有相同坐标的新queen并将其分配给board [col] [row].
我想知道是否有更好的方法来做到这一点.不知何故从"内部"改变对象的类.
通过使用chess.js库(请参阅此链接),我可以通过使用game_over()函数来了解棋类游戏是否完成。
但是我怎么知道谁赢了谁输了?
我写了一个简单的脚本,但输出不正确.你能给我建议如何解决吗?问题是关于棋盘上的白色或黑色方块:如果我使用带有字符串'd'和int(4)的def,它将返回白色,但它必须是黑色的?
def in_white(letter,integer):
list_letters_1 = ['a','c','e','g']
list_letters_2 = ['b','d','f','h']
list_numbers_1 = [1,3,5,7]
list_numbers_2 = [2,4,6,8]
print(list_numbers_1)
if str(letter) in list_letters_1 and int(integer) in list_numbers_1:
print("black")
elif str(letter) in list_letters_2 and int(integer) is list_numbers_2:
print("black")
else:
print("white")
in_white('d',4)
Run Code Online (Sandbox Code Playgroud) chess ×10
c ×2
c# ×2
java ×2
bit ×1
casting ×1
css ×1
html ×1
html-table ×1
if-statement ×1
inheritance ×1
javascript ×1
jvm ×1
lag ×1
optimization ×1
picturebox ×1
python ×1
scala ×1
statements ×1
struct ×1
winforms ×1