五子棋V1
利用void java.awt.Graphics.drawLine(int x1, int y1, int x2, int y2)函数画棋盘
Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.
利用void java.awt.Graphics.fillOval(int x, int y, int width, int height)函数画棋子
Fills an oval bounded by the specified rectangle with the current color.
其中(x,y)是圆的正接矩形左上点。
缺陷:画棋子时会造成闪屏等现象。
五子棋V2
利用图片作为棋子和棋盘。
BufferedImage image = null;
try {
image = ImageIO.read(new File("E:/ve_eclipse/workspace/fivechess/src/image/chesstable1.jpg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
g.drawImage(image, 0, 50, this);
界面最小化后再开启会变成新界面:重绘
利用chesses[][]存储的落子情况重绘
悔棋功能:
新建类Node 存储每个落子点的坐标和棋子颜色
List<Node> nodeList = new ArrayList<Node>(); 存储落子顺序
悔棋时Node java.util.List.remove(int index)函数
Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list
复盘功能:按照落子顺序重新下一遍。
关键是重绘和暂停。
重绘按钮的事件监听器:
jBut4.addActionListener(new ActionListener(){
/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
clearchesses();
blnstate = false;
javax.swing.SwingUtilities.updateComponentTreeUI(fcUI);
}
});
重绘和暂停:
if(!blnstate){
noderepaint(g);//根据nodelist重绘
}
myrepaint(g);//根据chesses[][]重绘
//根据落子顺序nodelist重绘
private void noderepaint(Graphics g){
for(int i = 0; i< nodeList.size(); i++){
Node node = nodeList.get(i);
chesses[node.getX()][node.getY()] = node.getColor();
myrepaint(g);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
重新开始功能:清空chesses[][] 和nodelist
界面刷新:void javax.swing.SwingUtilities.updateComponentTreeUI(Component c)
A simple minded look and feel change: ask each node in the tree to updateUI() -- that is, to initialize its UI property with the current look and feel.
五子棋V3
五子棋智能算法:
思路一:搜索对手落子点周围3*8个点中空格的情况。(经观察各个威胁到己方的棋局,在落子点三个棋子之内的概率最大)计算每个空格周围3*8个方向上各个方向上的棋子情况。选择分值最高的落子。。。。。属于防守型。。。。。不能判断己方形势。
思路二:每个棋子的落下,都会对整个局势产生影响,这种影响在该子周围4*8个之内,并且距离落子点越近,影响越大。连子具有指数型叠加效应,其中,+*+*+具有连子的相同叠加效应。都失败了得说。。。。。
希望能够提示对手最新落子点。。。。还没去写
另外按钮的显示总是迟延。。。。