FPGAアルテラCyclone IVのゲーム「Life」

ゲーム「Life」は、1970年にジョンコンウェイによって発明された有名なセルラーオートマトンです。 ゲームの本質は、「宇宙」をシミュレートすることです。この場合、閉じたエッジを持つ8x8の正方行列に実装されています。



ゲームプレイ



この場合、ゲームは組み込みのボタンとスイッチを使用してアルテラCyclone IV FPGAに実装されます。 プロセス全体は、条件付きで2つの動作モードに分けられます。第1世代の構成の選択と実際のシミュレーションです。



実装



ゲームはVerilogデザイン言語で実装され、入力モジュール、出力、アルゴリズムおよび基本、残りを接続する4つの基本モジュールで構成されています。



遷移アルゴリズム


コード内のプレイフィールドは、64要素のレジスタの形式で表示されます。 次世代への移行は、シーケンシャルロジックを使用して実行されます。



遷移関数
function [63:0]step; input [63:0]field; reg [63:0]new_field; reg [7:0]position; reg [7:0]count; integer x; integer y; begin new_field = field; for(x = 0; x < 8; x = x + 1 ) begin: iloop for(y = 0; y < 8; y = y + 1) begin: jloop count = neighbour_count(field,x,y); position = to_1d(x,y); if (count == 3) new_field[position] = 1; else if ((count < 2) || (count > 3)) new_field[position] = 0; end end step = new_field; end endfunction function [7:0]neighbour_count; input [63:0]field; input [7:0]x; input [7:0]y; reg [7:0]count; reg [7:0]position; begin count = 0; position = to_1d(x-1,y-1); count = count + field[position]; position = to_1d(x,y-1); count = count + field[position]; position = to_1d(x + 1, y - 1); count = count + field[position]; position = to_1d(x - 1, y); count = count + field[position]; position = to_1d(x + 1, y); count = count + field[position]; position = to_1d(x - 1, y + 1); count = count + field[position]; position = to_1d(x, y + 1); count = count + field[position]; position = to_1d(x + 1, y + 1); count = count + field[position]; neighbour_count = count; end endfunction function [7:0]to_1d; input [7:0]x; input [7:0]y; begin if (x >= 8'b11111111) x = x + 8'd8; else if (x >= 8'd8) x = x - 8'd8; if (y >= 8'b11111111) y = y + 8'd8; else if (y >= 8'd8) y = y - 8'd8; to_1d = x + y * 8'd8; end endfunction
      
      







入力/出力モジュール


出力モジュールは、16個の制御ピンを備えた標準の8x8 LEDマトリックスで動作します。 表示の制限により、画像は行に表示され、表示された行が連続的に変更されます。



入力モジュールは、画面更新とモード切り替えの3つのボタンで構成されています。 セットアップモードでは、3つのボタンがすべてアクティブになります-アクティブセルの選択、アクティブセルの状態の変更、画面の更新。 シミュレーションモードでは、画面の更新ボタンのみがアクティブになります。



作業例


画像






ソースコード



PSこの記事は学生研究の要件の1つです。スリッパを投げないよう強く強くお願いします。責任を負わないでください。



All Articles