首先简单介绍一下《生命游戏》

  生命游戏其实是一个零玩家游戏。它包括一个二维矩形世界,这个世界中的每个方格居住着一个活着的或死了的细胞。一个细胞在下一个时刻生死取决于相邻八个方格中活着的或死了的细胞的数量。如果相邻方格活着的细胞数量过多,这个细胞会因为资源匮乏而在下一个时刻死去;相反,如果周围活细胞过少,这个细胞会因太孤单而死去。具体如下图:

每个格子的生死遵循下面的原则:

  1. 如果一个细胞周围有3个细胞为生(一个细胞周围共有8个细胞),则该细胞为生(即该细胞若原先为死,则转为生,若原先为生,则保持不变) 。

  2. 如果一个细胞周围有2个细胞为生,则该细胞的生死状态保持不变;

  3. 在其它情况下,该细胞为死(即该细胞若原先为生,则转为死,若原先为死,则保持不变设定图像中每个像素的初始状态后依据上述的游戏规则演绎生命的变化,由于初始状态和迭代次数不同,将会得到令人叹服的优美图案)。

图案:

有三类图案:

第一类这种图案是固定不变的:

第二类:是按规律变化的:

第三类:是不断变化和移动的,但是有一定的周期性,最著名的就是  滑翔机:

Java实现代码:

 package com.cisco.gendwang;

 import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem; public class LifeGame extends JFrame
{
private final World world; public LifeGame(int rows, int columns)
{
world = new World(rows, columns);
new Thread(world).start();
add(world);
} public static void main(String[] args)
{
LifeGame frame = new LifeGame(40, 50); JMenuBar menu = new JMenuBar();
frame.setJMenuBar(menu); JMenu options = new JMenu("Options");
menu.add(options); JMenuItem arrow = options.add("Arrow");
arrow.addActionListener(frame.new ArrowActionListener()); JMenuItem square = options.add("Square");
square.addActionListener(frame.new SquareActionListener()); JMenu help = new JMenu("Help");
menu.add(help); frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1007, 859);
frame.setTitle("Game of Life");
frame.setVisible(true);
frame.setResizable(false);
} class ArrowActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
world.setArrow();
}
} class SquareActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
world.setSquare();
}
}
}
 package com.cisco.gendwang;

 import java.awt.Graphics;

 import javax.swing.JPanel;

 public class World extends JPanel implements Runnable
{
private final int rows;
private final int columns;
private final CellStatus[][] generation1;
private final CellStatus[][] generation2;
private CellStatus[][] currentGeneration;
private CellStatus[][] nextGeneration;
private volatile boolean isChanging = false; public World(int rows, int columns)
{
this.rows = rows;
this.columns = columns;
generation1 = new CellStatus[rows][columns];
for(int i = 0; i < rows; i++)
{
for(int j = 0; j < columns; j++)
{
generation1[i][j] = CellStatus.Dead;
}
} generation2 = new CellStatus[rows][columns];
for(int i = 0; i < rows; i++)
{
for(int j = 0; j < columns; j++)
{
generation2[i][j] = CellStatus.Dead;
}
} currentGeneration = generation1;
nextGeneration = generation2;
} @Override
public void run()
{
while(true)
{
synchronized(this)
{
while(isChanging)
{
try
{
this.wait();
} catch (InterruptedException e)
{
e.printStackTrace();
}
} repaint();
sleep(1); for(int i = 0; i < rows; i++)
{
for(int j = 0; j < columns; j++)
{
evolve(i, j);
}
} CellStatus[][] temp = null;
temp = currentGeneration;
currentGeneration = nextGeneration;
nextGeneration = temp; for(int i = 0; i < rows; i++)
{
for(int j = 0; j < columns; j++)
{
nextGeneration[i][j] = CellStatus.Dead;
}
}
}
}
} @Override
public void paintComponent(Graphics g)
{
super.paintComponent(g); for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
if(currentGeneration[i][j] == CellStatus.Active)
{
g.fillRect(j * 20, i * 20, 20, 20);
}
else
{
g.drawRect(j * 20, i * 20, 20, 20);
}
}
}
} public void setArrow()
{
setShape(arrow);
} public void setSquare()
{
setShape(square);
} private void setShape(int[][] shape)
{
isChanging = true; int arrowsRows = shape.length;
int arrowsColumns = shape[0].length; int minimumRows = (arrowsRows < rows) ? arrowsRows: rows;
int minimumColumns = (arrowsColumns < columns) ? arrowsColumns : columns; synchronized(this)
{
for(int i = 0; i < rows; i++)
{
for(int j = 0; j < columns; j++)
{
currentGeneration[i][j] = CellStatus.Dead;
}
} for(int i = 0; i < minimumRows; i++)
{
for(int j = 0; j < minimumColumns; j++)
{
if(shape[i][j] == 1)
{
currentGeneration[i][j] = CellStatus.Active;
}
}
} isChanging = false;
this.notifyAll();
}
} private void evolve(int x, int y)
{
int activeSurroundingCell = 0; if(isValidCell(x - 1, y - 1) && (currentGeneration[x - 1][y - 1] == CellStatus.Active))
{
activeSurroundingCell++;
} if(isValidCell(x, y - 1) && (currentGeneration[x][y - 1] == CellStatus.Active))
{
activeSurroundingCell++;
} if(isValidCell(x + 1, y - 1) && (currentGeneration[x + 1][y - 1] == CellStatus.Active))
{
activeSurroundingCell++;
} if(isValidCell(x + 1, y) && (currentGeneration[x + 1][y] == CellStatus.Active))
{
activeSurroundingCell++;
} if(isValidCell(x + 1, y + 1) && (currentGeneration[x + 1][y + 1] == CellStatus.Active))
{
activeSurroundingCell++;
} if(isValidCell(x, y + 1) && (currentGeneration[x][y + 1] == CellStatus.Active))
{
activeSurroundingCell++;
} if(isValidCell(x - 1, y + 1) && (currentGeneration[x - 1][y + 1] == CellStatus.Active))
{
activeSurroundingCell++;
} if(isValidCell(x - 1, y) && (currentGeneration[x - 1][y] == CellStatus.Active))
{
activeSurroundingCell++;
} if(activeSurroundingCell == 3)
{
nextGeneration[x][y] = CellStatus.Active;
}
else if(activeSurroundingCell == 2)
{
nextGeneration[x][y] = currentGeneration[x][y];
}
else
{
nextGeneration[x][y] = CellStatus.Dead;
}
} private boolean isValidCell(int x, int y)
{
if((x >= 0) && (x < rows) && (y >= 0) && (y < columns))
{
return true;
}
else
{
return false;
}
} private void sleep(int x)
{
try
{
Thread.sleep(1000 * x);
} catch (InterruptedException e)
{
e.printStackTrace();
}
} static enum CellStatus
{
Active,
Dead;
} private static final int[][] arrow = {
{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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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,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,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}
};
}

------------------------------------------ 更新2017年06月05日16:54:52 ------------------------------------------

项目地址:https://github.com/zpfbuaa/Game-Of-Life

项目代码:http://files.cnblogs.com/files/zpfbuaa/GameOfLife.rar

生命游戏/Game of Life的Java实现(转)的更多相关文章

  1. 生命游戏/Game of Life的Java实现

    首先简单介绍一下<生命游戏> 生命游戏其实是一个零玩家游戏.它包括一个二维矩形世界,这个世界中的每个方格居住着一个活着的或死了的细胞.一个细胞在下一个时刻生死取决于相邻八个方格中活着的或死 ...

  2. 生命游戏 Java

    本程序由四个类组成:其中Init_data,用于初始化各个活细胞的状态judge_state,用于判断下一代的细胞状态,并进行更新.set_color,用于给GUI界面中各个细胞涂色set_frame ...

  3. 实用---生命游戏 Java

    本程序由四个类组成: 其中Init_data,用于初始化各个活细胞的状态judge_state,用于判断下一代的细胞状态,并进行更新.set_color,用于给GUI界面中各个细胞涂色set_fram ...

  4. Java实现 蓝桥杯 生命游戏

    标题:生命游戏 康威生命游戏是英国数学家约翰·何顿·康威在1970年发明的细胞自动机. 这个游戏在一个无限大的2D网格上进行. 初始时,每个小方格中居住着一个活着或死了的细胞. 下一时刻每个细胞的状态 ...

  5. java实现第八届蓝桥杯生命游戏

    生命游戏 题目描述 康威生命游戏是英国数学家约翰·何顿·康威在1970年发明的细胞自动机. 这个游戏在一个无限大的2D网格上进行. 初始时,每个小方格中居住着一个活着或死了的细胞. 下一时刻每个细胞的 ...

  6. Java实现 LeetCode 289 生命游戏

    289. 生命游戏 根据百度百科,生命游戏,简称为生命,是英国数学家约翰·何顿·康威在1970年发明的细胞自动机. 给定一个包含 m × n 个格子的面板,每一个格子都可以看成是一个细胞.每个细胞具有 ...

  7. [LeetCode] Game of Life 生命游戏

    According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellul ...

  8. React项目(二):生命游戏

    引子 这是16年最后的一个练手项目,一贯的感觉就是,做项目容易,写说明文档难.更何况是一个唤起抑郁感觉的项目,码下的每个字,心就如加了一个千斤的砝码. 2016年,有些事我都已忘记,但我现在还记得.2 ...

  9. javascript小游戏--生命游戏

    昨天参加Code Retreat的活动,"Code Retreat是一个一天的集中练习的活动,专注于软件开发和设计的基础". 要了解更多信息可前往 CodeRetreat官网 通过 ...

随机推荐

  1. [编辑器]走上atom之路1

    祝大家新年快乐 我就是来卖个萌,逃- 正文 我最开始用atom是因为它看起来比较酷,我工作中主力还是使用pycharm,毕竟atom只是一个编辑器.我一 般只是用atom来写Markdown的文件.随 ...

  2. 【推荐】iOS带有加载网络图片进度的UIImageView

    UCZProgressView 是一个带有通用的圆形图片进度下载控件.动画效果不错 特性 Customizable indicator (line width, radius, and color) ...

  3. MVC怎么在当前视图中,传递参数给到另外一个视图?

    在TransData.cshtml视图中: <div> <!--在一个视图中,请求另外一个视图,并且将数据传到另外一个视图--> <!--视图中调用无返回值的方法,需要加 ...

  4. C#中方法的调用

    C#中方法的调用 1.同一个类中方法的调用: 静态方法可以直接调用静态方法 静态方法不能直接调用非静态方法,静态方法先生成. 非静态方法可以直接调用静态方法 如果静态方法要调用非静态的方法,必须使用实 ...

  5. KMP算法 - 求最小覆盖子串

    KMP与最小覆盖子串 最小覆盖子串:对于某个字符串s,它的最小覆盖子串指的是长度最小的子串p,p满足通过自身的多次连接得到q,最后能够使s成为q的子串. 比如: 对于s="abcab&quo ...

  6. 安装 Oracle P6 EPPM 16 R1 database for 12C

    . 打开命令提示符(Windows)或 终端(如果UNIX)和连接数据库使用以下命令: sqlplus sys/password@dbservicename as sysdba 连接到: sqlplu ...

  7. js跳转页面方法大全

    js跳转页面方法大全<span id="tiao">3</span><a href="javascript:countDown"& ...

  8. 【C#】OOP之继承那点事

    前言: 继承这点事,说多不多,说少不少,这里只描述了一些我认为的基础篇,望各位大神指教.本节参照了C#高级编程和Think in java对继承的描述,我个人认为OOP只是思想,故看明白一个就说通的, ...

  9. 整理的有用的一些EF的CommonDAL小封装

    CommonDAL封装: using System; using System.Collections.Generic; using System.Data.Entity; using System. ...

  10. asp.net.mvc 中form表单提交控制器的2种方法和控制器接收页面提交数据的4种方法

    MVC中表单form是怎样提交? 控制器Controller是怎样接收的? 1..cshtml 页面form提交 (1)普通方式的的提交