java跳棋击源代码 跳棋h5

Java跳棋算法问题这个其实和五子棋 象棋的寻址区别不大,都是最佳算法
其实主要看搜索深度的,我以前自己做过五子棋和象棋的java版本
有很多算法实现 你用alpha beta或者置换表都可以
验证做好的是最忧搜索 置换表 历史启发 , 现在不写那些了 代码不好找 你去网上搜索五子棋人工智能就应该有
用java语言编出一个西洋跳棋盘import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame();
JPanel boardPanel = new JPanel(new GridLayout(SCALE, SCALE));
final Cell[][] board = new Cell[SCALE][SCALE];
final JTextArea textArea = new JTextArea(15, 15);
ActionListener cellHandler = new ActionListener() {
public void actionPerformed(ActionEvent e) {
((Cell) e.getSource()).reverse();
display(textArea, board);
}
};
for (int i = 0; iboard.length;i) {
for (int j = 0; jboard[i].length;j) {
Cell cell = new Cell(i, j, false);
cell.addActionListener(cellHandler);
boardPanel.add(cell);
board[i][j] = cell;
}
}
display(textArea, board);
frame.add(boardPanel, BorderLayout.CENTER);
frame.add(new JScrollPane(textArea), BorderLayout.EAST);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
private static void display(JTextArea textArea, Cell[][] board) {
textArea.setText("");
for (Cell[] cells : board) {
for (Cell cell : cells)
textArea.append(cell.getText());
textArea.append("\n");
}
boolean value;
outter: for (int i = 0; iSCALE;i) {
value = https://www.04ip.com/post/board[i][0].value;
for (int j = 1; jSCALE;j)
if (value != board[i][j].value)
continue outter;
textArea.append("row "(i1)" has only "
(value ? 1 : 0)"s\n");
}
outter: for (int j = 0; jSCALE;j) {
value = https://www.04ip.com/post/board[0][j].value;
for (int i = 1; iSCALE;i)
if (value != board[i][j].value)
continue outter;
textArea.append("column "(j1)"has only "
(value ? 1 : 0)"s\n");
}
boolean flag = true;
value = https://www.04ip.com/post/board[0][0].value;
for (int i = 1; iSCALE;i)
if (value != board[i][i].value) {
flag = false;
break;
}
if (flag)
textArea.append("principal diagonal has only "
(value ? 1 : 0)"s\n");
flag = true;
value = https://www.04ip.com/post/board[0][SCALE - 1].value;
for (int i = 1; iSCALE;i)
if (value != board[i][SCALE - i - 1].value) {
flag = false;
break;
}
if (flag)
textArea.append("auxiliary diagonal has only "
(value ? 1 : 0)"s\n");
}
private static class Cell extends JButton {
private static final long serialVersionUID = 2653702443706288965L;
int row, col;
boolean value;
Cell(int row, int col, boolean value) {
this.row = row;
this.col = col;
this.value = https://www.04ip.com/post/value;
setText(value ? "1" : "0");
}
void reverse() {
value = https://www.04ip.com/post/!value;
setText(value ? "1" : "0");
}
}
private static final int SCALE = 8;
}
JAVA编写一个简单的跳棋游戏import java.awt.*;
import javax.swing.JFrame;
public class JumpChess extends JFrame{
public JumpChess(){
setSize(800,800);setVisible(true);
setBackground(Color.pink);
}
public void paint(Graphics g){g.setColor(Color.gray);int x=290;int y=140;int x1=330;
for(int row=1;row13;row){g.drawLine(x,y,x1,y);
x=x-20;
x1=x1 20;
y=y 30;
System.out.println();}
int x2=110;int y2=230;int x3=90;int y3=260;
for(int row=1;row13;row){g.drawLine(x2,y2,x3,y3);x2=x2 40;x3=x3 20;y3=y3 30;
System.out.println();
}
int x4=510;int y4=230;int x5=530;int y5=260;
for(int row=1;row13;row){g.drawLine(x4,y4,x5,y5);x4=x4-40;x5=x5-20;y5=y5 30;
System.out.println();
}
int x6=510;
Java 跳棋的程序 急~~先导入三个按钮图片?
正常显示的图片"Begin1.jpg"
鼠标移动到按钮上时显示的图片"Begin2.jpg"
按下鼠标时显示的图片"Begin1.jpg"
final ImageLoader imageBegin1 = new ImageLoader(sShell.getDisplay(), "Begin1.jpg");
final ImageLoader imageBegin2 = new ImageLoader(sShell.getDisplay(), "Begin2.jpg");
final ImageLoader imageBegin3 = new ImageLoader(sShell.getDisplay(),"Begin1.jpg");
创建按钮?
lblBegin = new Label(parent, SWT.NO_BACKGROUND);
lblBegin.setImage(imageBegin1.getImage());
lblBegin.setBounds(70, 40, 75, 38);
为按钮各事件写入代码?
lblBegin.addMouseTrackListener(new MouseTrackAdapter() {
public void mouseEnter(MouseEvent e) { //鼠标移动到按钮上方
lblBegin.setImage(imageBegin2.getImage());
}
public void mouseExit(MouseEvent e) { //鼠标从按钮上方移开
lblBegin.setImage(imageBegin1.getImage());
}
});
lblBegin.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
if (e.button == 1) {//按下鼠标左键
lblBegin.setImage(imageBegin3.getImage());//在这里写入单击事件代码
【java跳棋击源代码 跳棋h5】}
}
public void mouseUp(MouseEvent e) {
if (e.button == 1) {//释放鼠标左键
lblBegin.setImage(imageBegin2.getImage());
}
}
});
如图所示 , 当X坐标为1时,Y的坐标只能为5,当X坐标为2时,Y的坐标可以5或6 。于是我们建立一个数组:
final static private int[][] pos = {
{5,5}, //X坐标为1,Y的上限是5,下限是5
{5,6}, //X坐标为2,Y的上限是5,下限是6
{5,7}, //X坐标为3,Y的上限是5 , 下限是7
{5,8}, //X坐标为4,Y的上限是5,下限是8
{1,13}, //X坐标为5 , Y的上限是1,下限是13
{2,13}, //6
{3,13}, //7
{4,13}, //8
{5,13}, //9
{5,14}, //10
{5,15}, //11
{5,16}, //12
{5,17}, //13
{10,13}, //14
{11,13}, //15
{12,13}, //16
{13,13}, //17
};
在Position类中IsLegalPosition函数可以确定一个坐标是否合法
public static boolean IsLegalPosition(int x, int y) {
if ((x1) || (x17)) {
return false;
}
if ((ypos[x - 1][0]) || (ypos[x - 1][1])) {
return false;
}
return true;
}
3. 棋盘类(ChessBoard)中棋子和坐标的索引关系
?棋盘中所有Chess集合
private Chess[] chesses = null;//所有棋子对象都保存这个数组当中
下面函数可以根据索引号返回棋子对象
public Chess getChess(int index) {
return chesses[index];
}
?棋子和坐标的对应关系
private Position[] chessesPosition = null;//所有棋子坐标都保存在这个数组当中
下面函数可以根据棋子对象或棋子索引号返回坐标
public Position getPosition(Chess chess) {
return chessesPosition[chess.getindex()];
}
public Position getPosition(int index) {
return chessesPosition[index];
}
?坐标和棋子的对应关系
private Chess[][] chessesIndex = new Chess[17][17];//数组保存了17*17个棋子对象指针
下面函数可以根据棋子坐标返回该位置上的棋子,如果没有棋子返回Null
public Chess getChess(Position position) {
if (position == null){
return null;
}
return chessesIndex[position.getx() - 1][position.gety() - 1];
}
围棋java源代码就给你一个吧,只不过没有添加棋子,你自己搞吧 。import java.applet.*;
import java.awt.*;
import java.awt.event.*;
class ChessPad extends Panel implements MouseListener,ActionListener
{int x=-1,y=-1,棋子颜色=1;
Button button=newButton("重新开局");
TextField text_1=new TextField("请黑棋下子"),
text_2=new TextField();
ChessPad()
{setSize(440,440);
setLayout(null);setBackground(Color.pink);
addMouseListener(this);add(button);button.setBounds(10,5,60,26);
button.addActionListener(this);
add(text_1);text_1.setBounds(90,5,90,24);
add(text_2);text_2.setBounds(290,5,90,24);
text_1.setEditable(false);text_2.setEditable(false);
}
public void paint(Graphics g)
{for(int i=40;i=380;i =20)
{g.drawLine(40,i,400,i);
}
g.drawLine(40,400,400,400);
for(int j=40;j=380;j =20)
{g.drawLine(j,40,j,400);
}
g.drawLine(400,40,400,400);
g.fillOval(97,97,6,6);g.fillOval(337,97,6,6);
g.fillOval(97,337,6,6);g.fillOval(337,337,6,6);
g.fillOval(217,217,6,6);
}
public void mousePressed(MouseEvent e)
{if(e.getModifiers()==InputEvent.BUTTON1_MASK)
{x=(int)e.getX();y=(int)e.getY();
ChessPoint_black chesspoint_black=new ChessPoint_black(this);
ChessPoint_white chesspoint_white=new ChessPoint_white(this);
int a=(x 10)/2,b=(y 10)/2;
if(x/202||y/202||x/2019||y/2019)
{}
else
{
if(棋子颜色==1)
{this.add(chesspoint_black);
chesspoint_black.setBounds(a*20-7,b*20-7,16,16);
棋子颜色=棋子颜色*(-1);
text_2.setText("请白棋下子");
text_1.setText("");
}
else if(棋子颜色==-1)
{this.add(chesspoint_white);
chesspoint_white.setBounds(a*20-7,b*20-7,16,16);
棋子颜色=棋子颜色*(-1);
text_1.setText("请黑棋下子");
text_2.setText("");
}
}
}
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
public void actionPerformed(ActionEvent e)
{this.removeAll();棋子颜色=1;
add(button);button.setBounds(10,5,60,26);
add(text_1);text_1.setBounds(90,5,90,24);
text_2.setText("");text_1.setText("请黑棋下子");
add(text_2);text_2.setBounds(290,5,90,24);
}
}
class ChessPoint_black extends Canvas implements MouseListener
{ChessPad chesspad=null;
ChessPoint_black(ChessPad p)
{setSize(20,20);chesspad=p;addMouseListener(this);
}
public void paint(Graphics g)
{g.setColor(Color.black);g.fillOval(0,0,14,14);
}
public void mousePressed(MouseEvent e)
{if(e.getModifiers()==InputEvent.BUTTON3_MASK)
{chesspad.remove(this);
chesspad.棋子颜色=1;
chesspad.text_2.setText("");chesspad.text_1.setText("请黑棋下子");
}
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e)
{if(e.getClickCount()=2)
chesspad.remove(this);
}
}
class ChessPoint_white extends Canvas implements MouseListener
{ChessPad chesspad=null;
ChessPoint_white(ChessPad p)
{setSize(20,20);addMouseListener(this);
chesspad=p;
}
public void paint(Graphics g)
{g.setColor(Color.white);g.fillOval(0,0,14,14);
}
public void mousePressed(MouseEvent e)
{if(e.getModifiers()==InputEvent.BUTTON3_MASK)
{chesspad.remove(this);
chesspad.棋子颜色=-1;
chesspad.text_2.setText("请白棋下子");chesspad.text_1.setText("");
}
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e)
{if(e.getClickCount()=2)
chesspad.remove(this);
}
}
public class Chess extends Frame
{ChessPad chesspad=new ChessPad();
Chess()
{setVisible(true);
setLayout(null);
Label label=new Label("单击左键下子,双击吃子,右击棋子悔棋",Label.CENTER);
add(label);label.setBounds(70,55,440,26);
label.setBackground(Color.orange);
add(chesspad);chesspad.setBounds(70,90,440,440);
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);
}
});
pack();setSize(600,550);
}
public static void main (String args[])
{Chess chess=new Chess();
}
}
java跳棋击源代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于跳棋h5、java跳棋击源代码的信息别忘了在本站进行查找喔 。

    推荐阅读