Peg Solitaire。如何确定没有动作? [英] Peg Solitaire. How to determe that there is no moves left?

查看:96
本文介绍了Peg Solitaire。如何确定没有动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个由基本的Peg-Solitaire游戏组成的小项目。我正在使用GUI(按钮)。为了确定移动的可能性,我使用了get.Background()方法。那么我怎么能确定是否还有剩下的动作?

I am doing a little project that consists of a basic Peg-Solitaire game. I am using GUI(buttons). To determine the possibility of a move I use the get.Background() method. So how could I determine if there is no more moves left?

推荐答案

你知道什么动作是合法的 - 因为你必须在用户尝试时禁止非法动作。而且你知道电路板上的哪些空间被占用 - 否则你无法检查用户的移动!



所以看看板上的每个占用空间,看看是否它有任何法律举措。如有必要,模拟用户试图移动该部件并检查他可能做出的每一个可能的移动。如果您发现用户可以进行移动,则游戏尚未结束...
You know what moves are legal - because you have to forbid illegal moves when the user tries them. And you know which spaces on the board are occupied - otherwise you couldn't check the user moves!

So look at each occupied space on the board, and see if it has any legal moves. If necessary, "simulate" the user trying to move the piece and check every possible move he could make. If you find a move the user can make, the game isn't over...


您已经走错了路径。您可以从UI获得游戏的状态。它可以工作,但很容易理解为什么这不是一种强大的软件开发方式。随着更复杂的问题,它甚至可以将您的项目推向死胡同,将其弄得无法修复。只考虑一件事:您更改UI的颜色,您的游戏逻辑将停止工作。您必须更改比较检查背景的结果的颜色,它会再次起作用,对吗?整个想法都错了。



首先,你需要了解游戏本身有自己的逻辑。您需要单独开发其逻辑,因此它根本不依赖于UI。称之为数据模型,称之为模型和heliip;另一个孤立的部分可能是UI或View。并且想想他们之间应该是什么......



我建议你学习并分析以下架构模式的适用性 http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science) [ ^ ]):



MVVM - 模型视图模型,

http://en.wikipedia.org/wiki/Model_View_ViewModel [ ^ ],



MVC - 模型 - 视图 - 控制器,

http:// en.wikipedia.org/wiki/Model-view-controller [ ^ ]),



MVA - 模型 - 视图 - 适配器,

http://en.wikipedia.org/wiki/Model-view-adapter [ ^ ],



MVP - 模型 - 视图 - 演示者,

http://en.wikipedia.org/wiki/Model-view-演示者 [ ^ ]。

注意这些架构的动机。如果您了解它,您将能够创造更好的设计理念。



-SA
You already took a wrong path. You get the status of the game from the UI. It can work, but it's easy to understand why this is not a robust way of software development. With more complicated problems, it can even push your project to the dead end, mess it up beyond repair. Consider just one thing: you change the colors of the UI, and your game logic will stop working. You have to change the color you compared the result of checking the background with, and it will work again, right? The whole idea is wrong.

First of all, you need to understand that the game itself has its own logic. You need to develop its logic separately, so it would not depend on UI at all. Call it data model, call it just model&heliip; And another, isolated part could be UI or View. And think what should be between them…

I suggest you learn and analyze applicability of the following architectural patterns (http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)[^]):

MVVM — Model View View Model,
http://en.wikipedia.org/wiki/Model_View_ViewModel[^],

MVC — Model-View-Controller,
http://en.wikipedia.org/wiki/Model-view-controller[^]),

MVA — Model-View-Adapter,
http://en.wikipedia.org/wiki/Model–view–adapter[^],

MVP — Model-View-Presenter,
http://en.wikipedia.org/wiki/Model-view-presenter[^].
Pay attention for the motivation of those architectures. If you understand it, you would be able to create better design ideas.

—SA


这篇关于Peg Solitaire。如何确定没有动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆