简体   繁体   English

Java元胞自动机

[英]Cellular Automata in java

Can anyone help me ? 谁能帮我 ? Our teacher gave us a task it is about "game of life", he actually gave us the methods that we can use, but i really dont know how to start ! 我们的老师给了我们一个关于“生活游戏”的任务,他实际上给了我们可以使用的方法,但是我真的不知道该如何开始! he asked us to use 3 classes: class cellule,class ruleand class Automata(and the main of course) 他要求我们使用3类:细胞类,规则类和自动机类(当然还有主类)

package jeu_de_vie;


public class Cellule {
    private int state; // should be equal to 0 (if alive) or 1 (if dead)

    public Cellule(int state) { // constructor
        this.state = state;

    }
    public void SetEtat(int state){}

    public void Calculate_future_state(Cellule Cg, Cellule Cd,Regle R){} // to calculate the next state

    public boolean Equals (Cellule A,Cellule B){} // to verify if the cellular are equal
}

Looks like you have to write code for the 3 functions, this is how it should work: 看起来您必须为这3个函数编写代码,这是应该如何工作的:

SetEtat : SetEtat:

This function would be used to set the state of the cellule so it's simple and would work just like the constructor, take the parameter value and assign it to global variable state 此函数将用于设置单元格的状态,因此非常简单,并且可以像构造函数一样工作,获取参数值并将其分配给全局变量状态

public void SetEtat(int state){
    this.state = state;
}

Equals : 等于 :

According to me this function should return a boolean value so return type should be boolean instead of void, because you would use this for checking and you need a return value. 根据我的说法,此函数应返回布尔值,因此返回类型应为布尔值而不是void,因为您将使用此函数进行检查并且需要返回值。 For this to work, state needs to be public or you would need a getter function. 为了使此功能起作用,状态需要公开,否则您将需要getter函数。

public boolean Equals(Cellule A, Cellule B){
    return (A.state==B.state);
 }

The calculate future state function seems to be incomplete because there is no context of an object of type Regle. 由于没有Regle类型的对象的上下文,因此calculate future state函数似乎不完整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM