当前位置:文档之家› 五子棋源代码(2)

五子棋源代码(2)

五子棋源代码(2)
五子棋源代码(2)

设计题目:五子棋。

一、程序目的和功能

实现图形用户界面的五子棋双人对战。

二、各个类的功能说明

1.ChessPad

面板类,用于绘制棋盘,实现用鼠标进行走棋的动作。

棋盘如下:

关键代码:

public void paint(Graphics g){

for (int i=40;i<=400;i=i+20){

g.drawLine(40,i,400,i);

}

for(int j=40;j<=400;j=j+20){

g.drawLine(j,40,j,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)//走棋

2.ChessPoint_black

画布类,绘制黑棋,实现黑棋的悔棋,关键代码:

public void paint(Graphics g){

g.setColor(Color.black);g.fillOval(0,0,18,18);

}

public void mousePressed(MouseEvent e){

if(e.getModifiers()==InputEvent.BUTTON3_MASK){

chesspad.remove(this);

chesspad.棋子颜色=1;

chesspad.i--;

chesspad.text_3.setText("这是第"+chesspad.i+"步");

chesspad.text_2.setText("");

chesspad.text_1.setText("请黑棋下子");

}

}

3.ChessPoint_white

画布类,绘制白棋,实现白棋的悔棋,关键代码与ChessPoint_black类似。

4.Chess

窗口类,创建游戏主窗口以及游戏说明。

5.Judge类

自定义类,实现判断输赢的方法。核心算法:创建一个二维数组,其中储存的数据和棋子在棋盘上的位置一一对应,数组中某一数据等于1则表示棋盘上这个位置上是黑棋,若为-1则表示棋盘上这个位置上是白棋,每下一步棋就对整个棋盘进行查找是否有连续五颗颜色相同的棋子。

如:棋盘上的棋子位置:

则数组中的数据为:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 然后对表格中的数据分横向、纵向、东北、东南、西北、西南六个方向进行查找。关键代码:

int i,j,flag;

for(i=0;i<19;i++){//判断每一个纵向是否有连续的五颗颜色相同的棋子

flag=0;

for(j=0;j<19;j++)

if(a[i][j]==color){

flag++;

if (flag==5)

return true;}

else flag=0;

}

其他方向的算法类似。

6.主类

调用构造方法实现程序。

三、源代码:

import java.awt.*;

import java.awt.event.*;

import javax.swing.JOptionPane;

class ChessPad extends Panel implements MouseListener,ActionListener{//绘制棋盘,实现用鼠标进行走棋的动作

int array[][]=new int[19][19];//用于存放棋子位置的数组

int i=0;

int x=-1,y=-1;

int棋子颜色=1;

Button button=new Button("新游戏");

TextField text_1=new TextField("请黑棋下子"),

text_2=new TextField(),

text_3=new TextField();

ChessPad(){

setSize(440,440);

setLayout(null);setBackground(Color.cyan);

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);

add(text_3);

text_3.setBounds(200,5,80,24);

for(int i=0;i<19;i++)//数组初始化,所有数据为0

for(int j=0;j<19;j++)

{array[i][j]=0;}

text_1.setEditable(false);

text_2.setEditable(false);

}

public void paint(Graphics g){//绘制棋盘

for (int i=40;i<=400;i=i+20){

g.drawLine(40,i,400,i);

}

for(int j=40;j<=400;j=j+20){

g.drawLine(j,40,j,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){//走棋

int a=0,b=0;

ChessPoint_black chesspoint_black=new ChessPoint_black(this);

ChessPoint_white chesspoint_white=new ChessPoint_white(this);

if(e.getModifiers()==InputEvent.BUTTON1_MASK){

x=(int)e.getX();y=(int)e.getY();//获得棋子的坐标

if((x+5)/20<2||(y+5)/20<2||(x-5)/20>19||(y-5)/20>19)

{}//如果下在棋盘之外则什么也不做

else

{

i++;

text_3.setText("这是第"+i+"步");

a=(x+10)/20;b=(y+10)/20;

if(棋子颜色==1){

this.add(chesspoint_black);

chesspoint_black.setBounds(a*20-9,b*20-9,18,18);

棋子颜色=棋子颜色*(-1);//交换手

text_1.setText(" ");

text_2.setText("请白棋下子");

array[b-2][a-2]=1;//将棋子在棋盘上的位置一一对应储存在二维数组中

if (Judge.judge(array,1)){//判断黑棋赢

JOptionPane.showMessageDialog(this,"黑棋赢了!白棋加油啊!","黑棋赢",

https://www.doczj.com/doc/7111745663.html,RMATION_MESSAGE);

text_1.setText("黑棋赢!");

棋子颜色=2;

}

}

else if(棋子颜色==-1){

this.add(chesspoint_white);

chesspoint_white.setBounds(a*20-9,b*20-9,18,18);

棋子颜色=棋子颜色*(-1);

text_1.setText("请黑棋下子");

text_2.setText("");

array[b-2][a-2]=-1;

if (Judge.judge(array,-1))//判断白棋赢

{

JOptionPane.showMessageDialog(this,"白棋赢了!黑棋加油啊!","白棋赢",

https://www.doczj.com/doc/7111745663.html,RMATION_MESSAGE);

text_2.setText("白棋赢!");

棋子颜色=2;

removeMouseListener(this);

}

}

}

}

}

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);

add(text_3);

text_3.setBounds(200,5,80,24);

i=0;

text_3.setText("这是第"+i+"步");

for(int i=0;i<19;i++)

for(int j=0;j<19;j++)

{array[i][j]=0;}

addMouseListener(this);

}

}

class ChessPoint_black extends Canvas implements MouseListener{

ChessPad chesspad=null;

ChessPoint_black(ChessPad p){//创建一块画布

setSize(20,20);

addMouseListener(this);

chesspad=p;

}

public void paint(Graphics g){//在画布上绘制圆形,即棋子

g.setColor(Color.black);g.fillOval(0,0,18,18);

}

public void mousePressed(MouseEvent e){//单击鼠标右键的时候悔棋,从棋盘上移去该棋子并且步数减一

if(e.getModifiers()==InputEvent.BUTTON3_MASK){

chesspad.remove(this);

chesspad.棋子颜色=1;

chesspad.i--;

chesspad.text_3.setText("这是第"+chesspad.i+"步");

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){}

}

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,18,18);

}

public void mousePressed(MouseEvent e){

if(e.getModifiers()==InputEvent.BUTTON3_MASK){

chesspad.remove(this);

chesspad.棋子颜色=-1;

chesspad.i--;

chesspad.text_3.setText("这是第"+chesspad.i+"步");

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){}

}

public class Chess extends Frame{//创建主窗口

ChessPad chesspad=new ChessPad();

Chess(){

setVisible(true);

setLayout(null);

Label label1=new Label("五子棋",Label.CENTER);

add(label1);

label1.setBounds(70,55,440,26);

label1.setBackground(Color.gray);

Label label2=new Label("单击左键下棋,单击右键悔棋",Label.CENTER);

add(label2);

label2.setBounds(70,90,440,26);

label2.setBackground(Color.gray);

add(chesspad);//将棋盘加到窗口中

chesspad.setBounds(70,120,440,440);

addWindowListener(new WindowAdapter()

{public void windowClosing(WindowEvent e)

{System.exit(0);}

});

pack();

setSize(600,600);

}

public class Judge{//每下一步棋就对整个棋盘进行查找是否有连续五颗颜色相同的棋子。static boolean judge(int a[][],int color){

int i,j,flag;

for(i=0;i<19;i++){//判断每一个纵向是否有连续的五颗颜色相同的棋子

flag=0;

for(j=0;j<19;j++)

if(a[i][j]==color){ //如果数组中的数据等于给定的颜色则标志位自加

flag++;

if (flag==5)

return true;}

else flag=0;//一旦颜色不同则标志位清零

}

for(j=0;j<19;j++){//判断每一个横向是否有连续五颗颜色相同的棋子

flag=0;

for(i=0;i<19;i++)

if(a[i][j]==color)

{flag++;

if(flag==5)

return true;}

else flag=0;

}

for(j=4;j<19;j++){//从第4列开始判断判断每一个东北向是否有连续五颗颜色相同的棋子//因为第0到3列往东北方向无论如何凑不成五颗颜色相同的棋子

flag=0; int m=j;

for(i=0;i<=j;i++){

if(a[i][m--]==color){

flag++;

if(flag==5)

return true;}

else flag=0;}

}

for(j=14;j>=0;j--){//判断东南方向

flag=0; int m=j;

for(i=0;i<=18-j;i++){

if(a[i][m++]==color){

flag++;

if(flag==5)

return true;}

else flag=0;}

}

for(j=14;j>=0;j--){//判断西北方向

flag=0; int m=j;

for(i=18;i>=j;i--){

if(a[i][m++]==color){

flag++;

if(flag==5)

return true;}

else flag=0;}

}

for(i=14;i>=0;i--){//判断西南方向

flag=0; int n=i;

for(j=0;j<19-i;j++){

if(a[n++][j]==color){

flag++;

if(flag==5)

return true;}

else flag=0;}

}

return false;

}

}

public static void main(String args[]){ Chess chess=new Chess();

}

}

四、运行结果

Java五子棋游戏源代码(人机对战)

//Java编程:五子棋游戏源代码 import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; import java.io.PrintStream; import javax.swing.JComponent; import javax.swing.JPanel; /* *main方法创建了ChessFrame类的一个实例对象(cf), *并启动屏幕显示显示该实例对象。 **/ public class FiveChessAppletDemo { public static void main(String args[]){ ChessFrame cf = new ChessFrame(); cf.show(); } } /* *类ChessFrame主要功能是创建五子棋游戏主窗体和菜单**/ class ChessFrame extends JFrame implements ActionListener { private String[] strsize={"20x15","30x20","40x30"}; private String[] strmode={"人机对弈","人人对弈"}; public static boolean iscomputer=true,checkcomputer=true; private int width,height; private ChessModel cm; private MainPanel mp; //构造五子棋游戏的主窗体 public ChessFrame() { this.setTitle("五子棋游戏"); cm=new ChessModel(1); mp=new MainPanel(cm); Container con=this.getContentPane(); con.add(mp,"Center"); this.setResizable(false); this.addWindowListener(new ChessWindowEvent()); MapSize(20,15); JMenuBar mbar = new JMenuBar(); this.setJMenuBar(mbar); JMenu gameMenu = new JMenu("游戏");

基于Java五子棋游戏的设计源代码及全套资料

分类号: U D C:D10621-408-(2007)5738-0 密级:公开编号:21 成都信息工程学院 学位论文 基于Java的五子棋游戏的设计 论文作者姓名:赵小龙 申请学位类别:计算机科学与技术 申请学位类别:工学学士 指导教师姓名(职称):吴春旺 论文提交日期:2007年06月10日

基于Java的五子棋游戏的设计 摘要 五子棋作为一个棋类竞技运动,在民间十分流行,为了熟悉五子棋规则及技巧,以及研究简单的人工智能,决定用Java开发五子棋游戏。主要完成了人机对战和玩家之间联网对战2个功能。网络连接部分为Socket编程应用,客户端和服务器端的交互用Class Message定义,有很好的可扩展性,客户端负责界面维护和收集用户输入的信息,及错误处理。服务器维护在线用户的基本信息和任意两个对战用户的棋盘信息,动态维护用户列表。在人机对弈中通过深度搜索和估值模块,来提高电脑棋手的智能。分析估值模块中的影响精准性的几个要素,以及提出若干提高精准性的办法,以及对它们搜索的节点数进行比较,在这些算法的基础上分析一些提高电脑AI方案,如递归算法、电脑学习等。算法的研究有助于理解程序结构,增强逻辑思维能力,在其他人工智能方面也有很大的参考作用。 关键词:深度搜索;估值;电脑AI;五子棋;算法

Gobang Java-based games design Abstract As a sport, gobang is very popular in civil, in order to become familiar with gobang rules and techniques, and the study of simple artificial intelligence, I decide to use the Java to develope gobang games and complete the two functions including man-machine war and man-man war. Network Connection is Socket Programming for some applications, client and server interaction is definited by Class Message, which is a very good scalability, Client interface is responsible for the collection and maintenance of user input information, and error handling. Server users maintain online basic information and arbitrary two-time users of the chessboard of information, dynamic maintenance user list. During the man-machine players, it improves intelligence of the computer players through depth search and valuation module. Analyzes Module valuation of the precise elements, as well as a number of increased precision, and compares their search for nodes, which raises some computer AI programs on the basis of analysis, such as recursive algorithm, computer learning. Algorithm of procedures contribute to the understanding of the structure, logical thinking ability, In other areas of artificial intelligence has great references. . Key words:Search depth; Valuation; Computer AI; Gobang ; Algorithm

五子棋游戏代码(Java语言)

五子棋游戏代码(Java语言) import java.awt.*; import java.awt.event.*; import javax.swing.*; class mypanel extends Panel implements MouseListener { int chess[][] = new int[11][11]; boolean Is_Black_True; mypanel() { Is_Black_True=true; for(int i=0;i<11;i++) { for(int j=0;j<11;j++) { chess[i][j] = 0; } } addMouseListener(this); setBackground(Color.RED); setBounds(0, 0, 360, 360); setVisible(true); } public void mousePressed(MouseEvent e) { int x = e.getX(); int y = e.getY(); if(x < 25 || x > 330 + 25 ||y < 25 || y > 330+25) {return;} if(chess[x/30-1][y/30-1] != 0) {return;} if(Is_Black_True==true) { chess[x/30-1][y/30-1] = 1; Is_Black_True=false; repaint(); Justisewiner(); return; }

if(Is_Black_True==false) { chess[x/30-1][y/30-1]=2; Is_Black_True=true; repaint(); Justisewiner(); return; } } void Drawline(Graphics g) { for(int i=30;i<=330;i+=30) { for(int j = 30;j <= 330; j+= 30) { g.setColor(Color.GREEN); g.drawLine(i, j, i, 330); } } for(int j = 30;j <= 330;j+=30) { g.setColor(Color.GREEN); g.drawLine(30, j, 330, j); } } void Drawchess(Graphics g) { for(int i=0;i < 11;i++) { for(int j = 0;j < 11;j++) { if(chess[i][j] == 1) { g.setColor(Color.BLACK); g.fillOval((i+1)*30-8, (j+1)*30-8, 16, 16); } if(chess[i][j]==2) { g.setColor(Color.WHITE); g.fillOval((i+1)*30-8, (j + 1) * 30-8, 16, 16); }

五子棋报告-java

XXXX大学 XX学院 课程设计报告 课程名称:面向对象程序设计 题目名称:五子棋游戏设计 学生姓名: 专业班级: 指导教师:任晓强

一、课程设计目的与任务(四号、宋体、加黑、顶格) (1)掌握Java编程、面向对象的基础知识。 (2)较熟练地编写Java应用程序Application。 (3)了解Java的常用标准类库、编程技巧、异常处理。 (4)联系已学过的内容,巩固所学的理论,增强独立工作能力。(5)通过设计主要使学生有一个独立编写程序的过程,对理论学习及动手能力都有一个很大的提高。 (6)通过本次设计,进一步培养学生热爱专业的思想,同时对本专业综合素质的提高起一个积极的推动作用。 课程设计过程中,要严格遵守实践环节的时间安排,听从指导教师的指导。正确地完成上述内容,记录实习日记,规范完整地撰写出课程设计报告。 二、课程设计内容 1本设计题目的主要内容 设计一个15╳15围棋棋盘,由两玩家交替进行对战,并可以实现以下功能: 1.选择落子的先后顺序 2.重置棋盘 3.刷新重新开始 4.退出提示 并且规定退出者判为负,但退出过程中要有提示。以防不小心点错了。 最后判断某一方是否为五子连珠。 实现一个简单的多用户五子棋的游戏程序,包括如下两个界面 (1)选择对弈桌(执黑、执白)。 (2)在游戏界面,有开始,退出(游戏未结束、点退出自动判负); 2 设计思想与程序构架

程序流程图 程序的功能分配 a. 棋盘的绘制 public void draw_qipan(Graphics G) 添加按钮 Button b1=new Button("开始"); Button b2=new Button("重置游戏"); Label lblWin=new Label(" "); Checkbox ckbHB[]=new Checkbox[3]; Button exist = new Button("退出"); public void init(){ ckbHB[0]=new Checkbox("执白",ckgHB,false); ckbHB[1]=new Checkbox("执黑",ckgHB,false); ckbHB[2]=new Checkbox("观看",ckgHB, false); } c. 鼠标棋子的触发事件 public void mouseClicked(MouseEvent e) { Graphics g=getGraphics(); int x1,y1; x1=(); y1=(); if ()<20 || ()>300 || ()<20 || ()>300) {

基于JAVA的五子棋游戏系统设计与实现

基于JAVA的五子棋游戏系统设计与实 现

基于JAVA的五子棋游戏系统设计与实现专业电子信息工程 学生董永杰 指导教师曾玉

摘要 当前,随着计算机网络的的发展,以计算机技术和网络技术为核心的现代网络技术已经在现实生活和生产中得到了广泛的使用,已经成为多数人群的休闲方式,也为多数人所喜好。当然,为了满足没有网络同样能娱乐的要求,许多小游戏做成了单机和网络的双功能。 本软件使用JAVA语户端之间的连接,利用多线程技术言实现,经过对图形界面,绘图,布局管理器等去构造出游戏的单机功能,在此基础上,利用SCOKET的知识,建立起服务器与客来处理服务器端与客户端之间的数据传输,通信问题,使得客户端和服务器端之间能够同步的进行处理。 经过对软件的编写,更深入的理解了面向对象的概念,也体会到利用面向对象语言处理一些问题的优势。同时也加深了对多线程,流套接字等高级技术的理解。 关键词:多线程;流套接字;数据传输;同步。

ABSTRACT At present, With the rapid development of computer network. Taking computer technology and the network technology as the core, modern network technology is already used in the real life and the production and already became the leisure mode of the most people. And most people like them. Of course, it’s a pity that there still have some clients lacking of network because of various causes. In order to satisfy the above clients’ requirements. A large number of games ,usually nam ed as “small games” by players, are designed for involving two kinds of different function. The former game is often played by these players whose computers never connect with the network. It’s called for stand-alone version games. Just as its name implies, the later is named as online version games This software implemented with JAVA language, and according to the understanding of SCOKET ,GUI and paint image ichnology. Established in these foundation , the server co ects with the multi- client, and transmission the information between many clients using the multi-thread proceeding technology. it is very convenient for both client and server to do the synchronous processing. Through to the software compilation, deepen understanding and grasp to the technology above understanding and holding.

java五子棋小游戏实验报告(附源代码)

手机五子棋游戏的设计与实 现 专业: 姓名: 班级: 学号: 指导教师:

J2ME(Java 2 Micro Edition)是近年来随着各种不同设备,尤其是移动通信设备的飞速发展而诞生的一项开发技术。它因其“write once,run anywhere”的Java特性而提高了开发的效率。随着手机性能的不断提高,手机休闲娱乐应用将成为PC休闲娱乐应用之后又一重要业务增长点。棋类游戏规则单一,比较适合在手机等便携终端推广。 由于具有跨平台、易于移植、占用空间小的优势,J2ME成为移动应用开发平台的主流,并提供了很多用以支持移动应用软件的开发的API。现将该技术用于这次的手机游戏开发,可以实现游戏的快速开发,不但便于查看游戏运行过程中内存的占用量和程序的每一部分代码消耗了多少处理器时间,而且可以不断地优化代码,使代码具有高度的复用性、可扩展性、可维护性。 游戏的开发以J2ME为平台,利用Java技术,结合J2ME的MIDP技术,并对于程序设计思想,重要类、方法等展开讨论。在对弈部分,分析设计走棋算法,选择合适的方式组织成代码,实现基本的人工智能。过程中使用了J2ME中的CLDC/MIDP软件体系,主要运用了MID Profile的特定类的支持,来完成游戏的开发。 关键词:J2ME;CLDC;MIDP

J2ME is a kind of fast developing technology implemented on various devices especially mobile communication equipments. It improves the efficiency of the development process because of its "write once, run anywhere" nature. The development trend of the entertainment market based on the cell phone is very obvious because the handset performance enhances unceasingly. The entertainment market based on the cell phone will to be the new important business growth point follow the PC entertainment market. As the rules of a single chess game, it is more suitable for mobile phones and other portable terminal extension. J2ME has been the preferred platform for development because of its platform independent and compatibility, and provides a lot of APIs to support the development of mobile application software. The technology for mobile game development, can achieve the rapid development of the game. It is not only easy to observe the memory consumption and processor consumed time during the operation of the game, but also can optimize the code, so that the code has a high degree of reusability, scalability, maintainability. The game has designed by J2ME, the Java technology and the MIDP technology. I studied the procedure thought, the important class and the method. In the playing chess part, I have analyzed the algorithm, choosed the appropriate way to organize the code and realized the basic artificial intelligence. On the other hand,I learned software system of CLDC/MIDP and the specific class of the MID Profile to complete the game development. Key words: J2ME;CLDC;MIDP

五子棋(JAVA版)实习报告及原代码

实习报告 课程名称信息系统认知实习实习题目java五子棋专业 班级 学号 学生姓名 实习成绩 指导教师 2010年1月 前言

摘要 五子棋作为一个棋类竞技运动,在民间十分流行,为了熟悉五子棋规则及技巧,以及研究简单的人工智能,决定用Java开发五子棋游戏。主要完成了人机对战和玩家之间联网对战2个功能。网络连接部分为Socket编程应用,客户端和服务器端的交互用Class Message定义,有很好的可扩展性,客户端负责界面维护和收集用户输入的信息,及错误处理。服务器维护在线用户的基本信息和任意两个对战用户的棋盘信息,动态维护用户列表。在人机对弈中通过深度搜索和估值模块,来提高电脑棋手的智能。分析估值模块中的影响精准性的几个要素,以及提出若干提高精准性的办法,以及对它们搜索的节点数进行比较,在这些算法的基础上分析一些提高电脑AI方案,如递归算法、电脑学习等。算法的研究有助于理解程序结构,增强逻辑思维能力,在其他人工智能方面也有很大的参考作用。 1引言 1.1课题背景 五子棋是起源于中国古代的传统黑白棋种之一。现代五子棋日文称之为连珠,英译为Renju,英文称之为Gobang或FIR(Five in a Row 的缩写),亦有连五子、五子连、串珠、五目、五目碰、五格等多种称谓。 五子棋起源于古代中国,发展于日本,风靡于欧洲。对于它与围棋的关系有两种说法,一说早于围棋,早在“尧造围棋”之前,民间就已有五子棋游戏;一说源于围棋,是围棋发展的一个分支。在中国的文化里,倍受人们的青睐。本世纪初五子棋传入欧洲并迅速风靡全欧。通过一系列的变化,使五子棋这一简单的游戏复杂化、规范化,而最终成为今天的职业连珠五子棋,同时也成为一种国际 比赛棋。 Java语言是当今最为流行的程序设计语言之一作为一门非常优秀和极为健壮的编程语言,它同时具有的面向对象,与平台无关,分布式应用,安全,稳定和多线程等优良的特征,使用Java语言,不仅可以开发出功能强大的大型应用程序,而且Java语言本身突出的跨平台的特性也使得它特别适合于Internet上的应用开发,可以这样说,Java的出现使得所开发的应用程序“一次编写,处处可用”的 实现成为了可能。 1.2本课题研究的意义 近来随着计算机的快速发展,各种各样的电脑游戏层出不穷,使得我们能有更多的娱乐项目,而棋类游戏能起到锻炼人的思维和修身养性的作用,而且棋类游戏水平颇高,大有与人脑分庭抗礼之势。其中战胜过国际象棋世界冠军-卡斯帕罗夫的“深蓝”便是最具说服力的代表;其它像围棋的“手淡”、象棋的“将族”

五子棋-Java课程设计

《面向对象程序设计》 课程设计报告 实验时间:2010年10月26日 实验班级:********************** 实验报告总份(片)数: 1 份(片) 实验指导老师:***** ******* 设计小组 湖南省吉首市吉首大学 课程设计报告 简单的游戏——五子棋 小组成员(姓名、学号): **(组长)** ** ** ** ** 一、实验分工

二、开发环境(实验编译以及测试环境) 硬件环境: CPU:Intel 奔腾双核E5200 主频2.5GHz 内存:2G 软件环境: 操作系统:Windows 7 编程环境JDK7.0 开发工具:Eclipse SDK 三、使用环境(用户运行环境) 硬件环境: CPU主频在500MHZ以上,内存在128M以上 软件环境: JAVA运行环境+ Windows XP或Windows 2000 以上操作系统 目录 第一章总体设计.............................................................................................................................. 1 1.1设计的目的.......................................................................................................................... 1 1.2本系统的主要功能.............................................................................................................. 1 1.3系统包含的类及类之间的关系。...................................................................................... 1 1.4 Java源文件及其功能......................................................................................................... 2 1.5 项目构建思路..................................................................................................................... 2第二章模块功能介绍.................................................................................................................. 12 2.1主类Chess...................................................................................................................... 12

基于JAVA的五子棋游戏系统设计与实现

基于JA V A的五子棋游戏系统设计与实现专业电子信息工程 学生董永杰 指导教师曾玉

摘要 目前,随着计算机网络的的发展,以计算机技术和网络技术为核心的现代网络技术已经在现实生活和生产中得到了广泛的使用,已经成为多数人群的休闲方式,也为多数人所喜好。当然,为了满足没有网络同样能娱乐的要求,许多小游戏做成了单机和网络的双功能。 本软件使用JAVA语户端之间的连接,利用多线程技术言实现,通过对图形界面,绘图,布局管理器等去构造出游戏的单机功能,在此基础上,利用SCOKET 的知识,建立起服务器与客来处理服务器端与客户端之间的数据传输,通信问题,使得客户端和服务器端之间能够同步的进行处理。 通过对软件的编写,更深入的理解了面向对象的概念,也体会到利用面向对象语言处理一些问题的优势。同时也加深了对多线程,流套接字等高级技术的理解。 关键词:多线程;流套接字;数据传输;同步。

ABSTRACT ABSTRACT At present, With the rapid development of computer network. Taking computer technology and the network technology as the core, modern network technology is already used in the real life and the production and already became the leisure mode of the most peo ple. And most people like them. Of course, it’s a pity that there still have some clients lacking of network because of various causes. In order to satisfy the above clients’ requirements. A large number of games ,usually named as “small games” by players, are designed for involving two kinds of different function. The former game is often played by these players whose computers never connect with the network. It’s called for stand-alone version games. Just as its name implies, the later is named as online version games This software implemented with JAVA language, and according to the understanding of SCOKET ,GUI and paint image ichnology. Established in these foundation , the server co ects with the multi- client, and transmission the information between many clients using the multi-thread proceeding technology. it is very convenient for both client and server to do the synchronous processing. Through to the software compilation, deepen understanding and grasp to the technology above understanding and holding. Key Words: multiple thread, Socket, transmission-data, synchronism.

java五子棋实习报告

Java程序设计基础 实习报告 课程名称Java程序设计基础实习题目java五子棋 专业 班级 学号 学生姓名 指导教师

Java实习报告 一、JAVA技术介绍: Java技术是一门编程语言,也是一个平台,它基于Java虚拟机技术,借助这个东西建立了跨平台的优势。 Java编程语言与众不同之处在于:Java程序既是编译型的(转换为一种称为Java字节码的中间语言),又是解释型的(JVM 对字节码进行解析和运行)。编译只进行一次,而解释在每次运行程序时都会进行。编译后的字节码采用一种针对JVM 优化过的机器码形式;解释器是JVM 的实现。 二、摘要 五子棋作为一个棋类竞技运动,在民间十分流行,本课题主要完成了五子棋人机对战和玩家之间联网对战2个功能。网络连接部分为Socket编程应用,客户端和服务器端的交互用Class Message定义,有很好的可扩展性,客户端负责界面维护和收集用户输入的信息,及错误处理。服务器维护在线用户的基本信息和任意两个对战用户的棋盘信息,动态维护用户列表。在人机对弈中通过深度搜索和估值模块,来提高电脑棋手的智能。分析估值模块中的影响精准性的几个要素,以及提出若干提高精准性的办法,以及对它们搜索的节点数进行比较,在这些算法的基础上分析一些提高电脑AI方案,如递归算法、电脑学习等。算法的研究有助于理解程序结构,增强逻辑思维能力,在其他人工智能方面也有很大的参考作用。

三、课题分析与设计 1)键盘上事先设定8个按键,分作两组,每组四个,分别代表两个人 用来控制棋子的上下左右键。 2)绘制棋盘,15条横线,15条竖线,在直线交点处下棋子(实心圆形)。 3)黑子先行,黑白交替下子,在棋盘上设定一个与棋盘格大小边长相 等的正方形,初始状态,正方形的中心位于期盼的中心点。当一方 欲走棋的时候,应用四个按键来控制所要下棋的位置,每按一次按 键,正方形都要向相应方向移动一个格,并且让喇叭发出某种声音,将要移出边界时,发出另一种警告声音并不让其移出边界。当按下 回车键时,应在正方形所在位置放下一个棋子,然后此组按键不能 操作,换另一个人下棋,用另一组按键,规则同前。 4)当任何一方有五个棋子沿着横,竖,斜连在一起时,系统自动判断 赢棋,并显示黑方或白方胜利。棋局结束后,任何一方均不能继续 操作。

Java五子棋设计报告

南京晓庄学院 《JAVA程序设计》 课程设计报告 题目: 五子棋游戏的设计与实现 姓名: 陶野 学号: 班级: 12软件工程转本2班 指导教师: 王峥 完成时间7月1日 成绩: 信息工程学院 2015年6月

目录

五子棋游戏的设计与实现 1引言 五子棋相传起源于四千多年前的尧帝时期,比围棋的历史还要悠久,可能早在“尧造围棋”之前,民间就已有五子棋游戏。有关早期五子棋的文史资料与围棋有相似之处,因为古代五子棋的棋具与围棋是完全相同的。在上古的神话传说中有“女娲造人,伏羲做棋”一说,《增山海经》中记载:“休舆之山有石焉,名曰帝台之棋,五色而文状鹑卵。”李善注引三国魏邯郸淳《艺经》中曰:“棋局,纵横各十七道,合二百八十九道,白黑棋子,各一百五十枚”。这段虽没明讲是何种棋类,但至少知道远古就以漂亮的石头为棋子。因而规则简单的五子棋也可能出自当时,并是用石子作棋子。亦有传说,五子棋最初流行于少数民族地区,以后渐渐演变成围棋并在炎黄子孙后代中遍及开来。 1.1系统开发背景 在计算机逐步渗入社会生活各个层面的今天,计算机已经成为了人们日常生活中的一部分, 越来越多的人使用计算机办公、娱乐等等。在这其中,系统自带的小游戏也占据了相当重要的 地位,与那些网络游戏和3D游戏相比,它有编写简单容易上手等特点,非常适合人们在完成工 作的时候适当的娱乐要求。这些小游戏大都是以益智和娱乐为目的,不仅给紧张工作的人们以 放松,还可以让人们的大脑得到开发。 1.2完成的主要工作 设计一个15╳15围棋棋盘,由两玩家交替进行对战,并可以实现以下功能: 1.选择黑子先下 2.设置双方下棋总共时长 3.刷新重新开始 4.悔棋 5.认输 6.退出提示 实现一个简单的多用户五子棋的游戏程序,包括如下两个界面 (1)选择对弈桌(执黑、执白)。 (2)在游戏界面,有开始,退出(游戏未结束、点退出自动判负);

基于Java的“网络五子棋”游戏的设计和实现(含源文件)

基于Java的“网络五子棋”游戏的设计和实现——网络版客户端 学生:xxx 指导教师:xx 内容摘要:目前,随着计算机网络的发展,以计算机技术和网络技术为核心的现代网络技术已经在现实生活和生产中得到了广泛的使用,休闲类网络游戏集趣味性,娱乐性,互动性和益智性于一体,已经成为多数人群的休闲方式,也为多数人所喜好。 本设计收集了关于JAVA基础的书籍,着重收录了关于SOCKET编程的内容,找到了五子棋概述和规则的资料,查阅了网络通信技术的相关论文,同时也参考了很多关于五子棋实现的程序资料以及关于JAVA开发工具的介绍的文档。在期间,我学习了多线程技术、双缓冲技术、数据传输技术、SOCKET编程技术,研究了网络通信原理、JAVA编写原理等一系列的原理。开发了网络五子棋网络通信代码,实现了网络聊天、数据传输、网络通信、界面组织如:棋盘、建立服务器、连接到服务器、系统设置、我要参赛等功能。通过对以上技术的学习和研究,利用SOCKET编程,能服务器与客户端之间的连接,利用多线程技术完成了服务器端与客户端之间的数据传输、网络通信,使得两个客户端能够同步的进行处理。在加载图片以及绘制棋盘方面,采用双缓冲技术消除屏幕的闪烁现象。达到了预期的效果。 关键词: 多线程 SOCKET 客户端网络通信

Design and realization of the web gobang game based on java——client module Abstract: At present, with the development of computer network, computer technology and network technology as the core of modern network technology has in real life and production has been widely used. Recreational type of network games consists of interesting, entertaining, interactivity and beneficial intelligence. It has become a way of entertainment to many people, and has been loved. Much of the information collected in this design,such as many books based on the JAVA, focus on the contents of SOCKET programming, Find information about the web gobang game, Access to the relevant papers, Reference to a lot of program information on achieving The web gobang game and introduction to JAVA development tools on the document. In the period, I learned a series of principles,For example Multi-threading technology, double-buffering technology, data transmission technology, SOCKET programming technique to study the principle of network communication, JAVA writing principles. Internet chat, data transmission, network communications, interfaces structure, such as: the board, establishing server, connecting server, option had been realized. I know these technologies through studying and researching, I using of SOCKET programming, server and client can be connecting, i using of multi-threading technology to complete the server side and client-side data transmission and the client can synchronize the two processtion. Pictures and drawing board loading, I using of double-buffering to eliminate screen flicker. Keywords:multi-threaded socket client network communication

java编程五子棋全程(完整版)

下面的源代码分为4个文件; (1)chessClient.java:客户端主程序。 (2)chessInterface.java:客户端的界面。 (3)chessPad.java:棋盘的绘制。 (4)chessServer.java:服务器端。 可同时容纳50个人同时在线下棋,聊天。 /********************************************************************************************* 1.chessClient.java **********************************************************************************************/ import java.awt.*; import java.awt.event.*; import java.io.*; import https://www.doczj.com/doc/7111745663.html,.*; import java.util.*; class clientThread extends Thread { chessClient chessclient; clientThread(chessClient chessclient) { this.chessclient=chessclient; } public void acceptMessage(String recMessage) { if(recMessage.startsWith("/userlist ")) { StringTokenizer userToken=new StringTokenizer(recMessage," "); int userNumber=0; https://www.doczj.com/doc/7111745663.html,erList.removeAll(); https://www.doczj.com/doc/7111745663.html,erChoice.removeAll(); https://www.doczj.com/doc/7111745663.html,erChoice.addItem("所有人"); while(userToken.hasMoreT okens()) { String user=(String)userToken.nextToken(" "); if(userNumber>0 && !user.startsWith("[inchess]")) { https://www.doczj.com/doc/7111745663.html,erList.add(user);

相关主题
文本预览
相关文档 最新文档