나는 단순한 삶의 게임을 만들었습니다.생명의 게임 -이 알고리즘은 무엇입니까
//should return true if there were any changes to any "living" state
bool Algorithm.runOver(Cell target)
{
if (target.Occupied && !target.excluded)
{
target.Right.populate();
target.Left.populate();
target.Top.populate();
target.Bot.populate();
target.Right.excluded = true;
target.Left.excluded = true;
target.Top.excluded = true;
target.Bot.excluded = true;
return true;
}
else
{
return false;
}
}
제외하고 이미 알고리즘은 모든 실행이 완료 거짓 매번에 resetted되어 실행 여기에
class Cell
{
public Cell(MainWindow correspondingMainWindow){
this.mainWindow = correspondingMainWindow;
}
public bool excluded;
public Boolean Occupied { get; set; }
public Control correspondingPanel;
private int[] coordinates;
private MainWindow mainWindow;
public int[] Coordinates
{
get { return this.coordinates; }
set {
if(value.Length != 2)
{
throw new ArgumentException();
}
else if(value[0] < 0 || value [1] < 0
|| value[0] > Settings.FIELDWIDTH
|| value[1] > Settings.FIELDHEIGHT)
{
throw new ArgumentException();
}
else{
correspondingPanel = mainWindow.FieldArea.Controls
.Find(String.Format("panel{0}_{1}", value[0], value[1]), true)
.FirstOrDefault();
this.coordinates = value;
}
}
}
//Surrounding Cells in the 3x3 around the current cell
//this is to speed up the updating as soon as the algorithm runs on many cells
public Cell Top { get; set; }
public Cell TopRight { get; set; }
public Cell Right { get; set; }
public Cell BotRight { get; set; }
public Cell Bot { get; set; }
public Cell BotLeft { get; set; }
public Cell Left { get; set; }
public Cell TopLeft { get; set; }
public void die()
{
this.Occupied = false;
this.correspondingPanel.BackColor = Color.Beige;
}
public void populate()
{
this.Occupied = true;
this.correspondingPanel.BackColor = Color.DarkRed;
}
}
문제의 알고리즘 : 실제 물건 일 경우
이 내 세포입니다 한 번 세포. 이것은 walkUver()의 호출을이 워크에서 업데이트 된 Cell에서 막는 것입니다.
지금 내 필드의 왼쪽 상단 모서리 (간단한 뱀 필드와 같은)에서 셀을 가져 와서 표시하고 알고리즘을 실행하면 첫 번째 실행 후 변경이 중지됩니다.
실제로 설계된 방식으로 셀을 업데이트하지만 그 다음에 중지됩니다.
나는 내 셀을 프로그램의 정적 목록에 저장한다. (나는 올바르게해야 작동 할 때까지 가장 쉬운 방법이다). 셀에는 일치시킬 패널이 있습니다. 이러한 패널은 FieldArea라는 GroupBox에 있습니다. 그들은 몇 가지 정적 상수 설정 (좌표에 대한 집합 유효성 검사에서 볼 수 있음)을 기반으로 동적으로 생성됩니다.
세포가 패널에 정확하게 일치한다고 확신합니다. 이 문제는 왼쪽 상단 (0,0)에서 오른쪽 아래까지 FieldArea를 통해 대각선에서 발생하는 것으로 보입니다. 다른 시작점이 올바르게 작동합니다. 어떻게 든 더 많은 양의 세포가 "꼭대기"에서 왔을 때 세포는 필드의 상단과 좌측 가장자리에 경계선을 형성합니다.
지금 질문 : 내가 뭘 잘못하고 있니? 내 필드가 올바르게 작동하지 않는 이유는 무엇입니까?
문제가 해결되지 않으면 제 의견을 잊어주십시오. –