Lights out game algorithm

后端 未结 4 386
闹比i
闹比i 2020-11-29 11:00

It\'s a homework. I have to design and lights out game using backtracking description is below.

The game consists of a 5-by-5 grid of lights; when the game starts, a

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 11:23

    As already suggested, you should first form a set of simultaneous equations.

    First thing to note is that a particular light button shall be pressed at most once because it does not make sense to toggle the set of lights twice.

    Let Aij = Light ij Toggled { Aij = 0 or 1 }
    

    There shall be 25 such variables.

    Now for each of the lights, you can form an equation looking like

    summation (Amn) = 0. { Amn = 5 light buttons that toggle the light mn }
    

    So you will have 25 variables and 25 unknowns. You can solve these equations simultaneously.

    If you need to solve it using backtracking or recursion you can solve the equations that way. Just assume an initial value of variables, see if they satisfy all the equations. If not, then back track.

提交回复
热议问题