HDLBits-Exams/ece241 2013 q4、Lemmings1、Lemmings2、Lemmings3、Lemmings4

这篇博客通过一系列Lemmings问题,介绍如何使用有限状态机(FSM)模拟Lemmings的行为,包括左右行走、碰撞转向、掉落、挖掘和死亡条件。在Lemmings的2D世界中,Lemmings会根据地面情况、碰撞和指令改变行动,FSM需考虑这些因素来设计不同状态之间的转换。
摘要由CSDN通过智能技术生成

目录

Exams/ece241 2013 q4

Lemmings1

Lemmings2 

Lemmings3

Lemmings4


Exams/ece241 2013 q4

题目见网页图片。

module top_module (
    input clk,
    input reset,
    input [3:1] s,
    output fr3,
    output fr2,
    output fr1,
    output dfr
); 
    parameter nf0=0, nf1=1, nf2=2, nf3=3; //四个状态,根据表格从上到下
    reg [1:0] state, next; //现在的状态state和下一个状态next
    always @(*) begin
        case (s)  //根据输入确定next
            3'b000: next=nf3;   //全零意味着一个都没有起作用,水位低于S1
            3'b001: next=nf2;
            3'b011: next=nf1;
            3'b111: next=nf0;
        endcase
    end
    
    always @(posedge clk) begin        
        if(reset) begin
            state<=nf3;
            dfr<=1;
        end
        else begin  //在3个fr状态改变的时候,dfr的值也要改变,但下一个dfr的值取决于state和next
            if (state < next) begin
                dfr<=1;
                state<=next; end
            else if (state > next) begin
                dfr<=0;
                state<=next; end
            else begin
                dfr<=dfr;
                state<=next; end
    end
    end
    
    always @(*) begin
        case(state)
            nf0: {fr3,fr2,fr1}=3'b000;
            nf1: {fr3,fr2,fr1}=3'b001;
            nf2: {fr3,fr2,fr1}=3'b011;
            nf3: {fr3,fr2,fr1}=3'b111;
        endcase
    end

endmodule

Lemmings1

The game Lemmings involves critters with fairly simple brains. So simple that we are going to model it using a finite state machine.

In the Lemmings' 2D world, Lemmings can be in one of two states: walking left or walking right. It will switch directions if it hits an obstacle. In particular, if a Lemming is bumped on the left, it will walk right. If it's bumped on the right, it will walk left. If it's bumped on both sides at the same time, it will still switch directions.

Implement a Moore state machine with two states, two inputs, and one output that models this behaviour.

 思路:在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值