算24点计算器游戏

24点游戏,算24点,24点计算器,24点游戏计算器,电脑帮你算24点
[卜易居免费查询大全
&&电脑帮你算24点 by
&&扑克牌算24点游戏:随便抽出四张牌,花牌算1点,谁先列出算式者为胜。本系统是电脑给您的24点算法,最难的24点也能给你算出来。
24 点 游戏
第一个数字
第二个数字
第三个数字
第四个数字
卜易居算命测试大全
占卜小游戏页面导航:
→ 正文内容 C#实现的算24点游戏算法
C#实现的算24点游戏算法实例分析
这篇文章主要介绍了C#实现的算24点游戏算法,实例分析了算24点游戏相关的运算技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了C#实现的算24点游戏算法。分享给大家供大家参考。具体如下:
using System.Collections.G
using System.L
using System.T
using System.IO;
namespace Calc24Points
public class Cell
public enum Type
public int N
public char S
public Type T
public Cell R
public Cell L
/// &summary&
/// 符号优先级
/// &/summary&
public int Priority
if (Typ == Type.Signal)
switch (Signal)
case '+': return 0;
case '-': return 0;
case '*': return 1;
case '/': return 1;
default: return -1;
return -1;
/// &summary&
/// 基本单元构造函数
/// &/summary&
/// &param name="t"&单元类型,数值或符号&/param&
/// &param name="num"&数值&/param&
/// &param name="sig"&符号&/param&
public Cell(Type t, int num, char sig)
public Cell()
Number = 0;
Typ = Type.N
public Cell(Cell c)
Number = c.N
Signal = c.S
public class Calc24Points
StringWriter m_
public Calc24Points(int n1, int n2, int n3, int n4)
m_cell = new Cell[8];
m_cell[0] = new Cell(Cell.Type.Number, n1, '?');
m_cell[1] = new Cell(Cell.Type.Number, n2, '?');
m_cell[2] = new Cell(Cell.Type.Number, n3, '?');
m_cell[3] = new Cell(Cell.Type.Number, n4, '?');
m_cell[4] = new Cell(Cell.Type.Signal, 0, '+');
m_cell[5] = new Cell(Cell.Type.Signal, 0, '-');
m_cell[6] = new Cell(Cell.Type.Signal, 0, '*');
m_cell[7] = new Cell(Cell.Type.Signal, 0, '/');
m_express = new int[7];
m_string = new StringWriter();
public override string ToString()
if (m_exp == null)
PutCell(0);
m_exp = m_string.ToString();
if (m_exp != "") return m_
/// &summary&
/// 在第n位置放置一个单元
/// &/summary&
/// &param name="n"&&/param&
void PutCell(int n)
if (n &= 7)
if (Calculate())
Formate();
int end = 8;
if (n & 2) end = 4;
for (int i = 0; i & ++i)
m_express[n] =
if (CheckCell(n)) PutCell(n + 1);
if (m_stop)
/// &summary&
/// 检查当前放置是否合理
/// &/summary&
/// &param name="n"&&/param&
/// &returns&&/returns&
bool CheckCell(int n)
int nums = 0, sigs = 0;
for (int i = 0; i &= ++i)
if (m_cell[m_express[i]].Typ == Cell.Type.Number) ++
if (nums - sigs & 1)
if (m_cell[m_express[n]].Typ == Cell.Type.Number)
//数值不能重复,但是符号可以重复
for (int i = 0; i & ++i) if (m_express[i] == m_express[n])
if (n == 6)
if (nums != 4 || sigs != 3)
if (m_cell[m_express[6]].Typ != Cell.Type.Signal)
/// &summary&
/// 计算表达式是否为24
/// &/summary&
/// &returns&返回值true为24,否则不为24&/returns&
bool Calculate()
double[] dblStack = new double[4];
int indexStack = -1;
for (int i = 0; i & 7; ++i)
if (m_cell[m_express[i]].Typ == Cell.Type.Number)
dblStack[indexStack] = m_cell[m_express[i]].N
switch (m_cell[m_express[i]].Signal)
dblStack[indexStack - 1] = dblStack[indexStack - 1] + dblStack[indexStack];
dblStack[indexStack - 1] = dblStack[indexStack - 1]-+ dblStack[indexStack];
dblStack[indexStack - 1] = dblStack[indexStack - 1] * dblStack[indexStack];
dblStack[indexStack - 1] = dblStack[indexStack - 1] / dblStack[indexStack];
if (Math.Abs(dblStack[indexStack] - 24) & 0.1)
/// &summary&
/// 后缀表达式到中缀表达式
/// &/summary&
void Formate()
Cell[] c = new Cell[7];
for (int i = 0; i & 7; ++i) c[i] = new Cell(m_cell[m_express[i]]);
int[] cStack = new int[4];
int indexStack = -1;
for (int i = 0; i & 7; ++i)
if (c[i].Typ == Cell.Type.Number)
cStack[indexStack] =
c[i].Right = c[cStack[indexStack]];
c[i].Left = c[cStack[indexStack]];
cStack[indexStack] =
ToStringFormate(c[cStack[indexStack]]);
void ToStringFormate(Cell root)
if (root.Left.Typ == Cell.Type.Number)
m_string.Write(root.Left.Number);
m_string.Write(root.Signal);
if (root.Priority & root.Left.Priority)
m_string.Write("(");
ToStringFormate(root.Left);
m_string.Write(")");
else ToStringFormate(root.Left);
m_string.Write(root.Signal);
if (root.Right.Typ == Cell.Type.Number) m_string.Write(root.Right.Number);
if (root.Priority &= root.Right.Priority)
m_string.Write("(");
ToStringFormate(root.Right);
m_string.Write(")");
else ToStringFormate(root.Right);
希望本文所述对大家的C#程序设计有所帮助。
您可能感兴趣的文章:
上一篇:下一篇:
最 近 更 新
热 点 排 行
12345678910您的位置: &
手机扫描二维码下载
本站仅创建用户沟通交流的平台,所展示的安卓游戏资源内容来自于第三方上传分享,版权问题均与我站无关。资源仅作为用户间分享讨论之用,除开发商授权外不以盈利为目的。如该游戏触犯了您的权利,请申诉!邮箱:
这里为你提供了精彩的安卓数字游戏大全,有用简单有趣的数字或者文字组成的,并带有逻辑性的游戏;也有通过复杂的文字或数字组成的逻辑游戏,让游戏者回答的类型;还...
益智游戏是指那些通过一定的逻辑,来完成一定任务的小游戏。益智游戏不仅是小孩子们的专属,同时也适合年轻人玩。益智游戏能够增强自身的逻辑分析能力和思维敏捷性。...
本类最新游戏排行榜
休闲游戏游戏排行榜
35275次下载
55938次下载
61913次下载
4969次下载
3890次下载
1437次下载
86358次下载巧算24点游戏讲座_图文_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
文档贡献者
评价文档:
巧算24点游戏讲座
巧​算4​点​游​戏​讲​座
大小:211.00KB
登录百度文库,专享文档复制特权,财富值每天免费拿!
你可能喜欢您所在的位置: >
最多人玩的游戏合集
Copyright (C)
京ICP备号-3 北京冰枫天下科技有限公司
游戏作品版权归原作者享有,如无意之中侵犯了您的版权,请您按照《版权保护指引》来信告知,本网站将应您的要求删除。
温馨提示:适度游戏娱乐,沉迷游戏伤身,合理安排时间,享受快乐生活......

我要回帖

更多关于 24点闯关 的文章

 

随机推荐