用1,2,3分别代表石头剪刀布,输入甲乙的猜 拳选择输出甲乙猜拳结果。(分支结构)。C语言程序设计

用1,2,3分别代表石头剪刀布,输入甲乙的猜 拳选择输出甲乙猜拳结果。(分支结构)。C语言程序设计,第1张

void func(int a,int b)

{

int num=0;

if((a==1)&&(b==1))

printf("打平\n");

else if((a==1)&&(b==2))

printf("甲获胜\n");

else if((a==1)&&(b==3))

printf("乙获胜\n");

else if((a==2)&&(b==1))

printf("乙获胜\n");

else if((a==2)&&(b==2))

printf("打平\n");

else if((a==2)&&(b==3))

printf("甲获胜\n");

else if((a==3)&&(b==1))

printf("甲获胜\n");

else if((a==3)&&(b==2))

printf("乙获胜\n");

else if((a==3)&&(b==3))

printf("打平\n");

}

导语:很多时候和朋友想要竞争某种东西而迟迟没有结果的时候就会选择猜拳,下面就由我为大家分享几个猜拳必胜的结果,希望对大家有所帮助!

猜拳必胜技巧

石头、剪子、布”,又被称作“剪子、包袱、锤”或“猜拳”,在北京叫做“猜(cèi)丁壳”,东北等地称作“定钢锤”。这个游戏在世界范围内广泛通用。而近期用这个民间游戏命名的**与电视剧也登上了银幕。

1、第一局先出布,或者剪刀。新手喜欢以石头开局,因此出布的`人很容易拿下开门红。然而如果你与老手过招,并且他们觉得你是菜鸟,那么他们就会先出布;要是他们觉得你的级别高于菜鸟,就会出剪刀。这样你的最佳选择就是出剪刀——要么平局,要么获胜。

2、当你有所迟疑时,就出布吧。人们最经常出石头,最少出剪刀。

3、根据对手上局的手势出拳,让对手的上局拳法击败你将要亮出的拳法。没有计划时,人们乐于击败自己上局的手势。例如某人上一局出了布,下一局就会出剪刀,所以你该出石头了。

4、注意连续两次相同的出拳。很少有人会连续三次出一样的手势,如果对方连续两局出了石头,下一局很有可能会出剪刀或者布,因此你该出剪刀,这样至少落个平局。

科学家们根据博弈论得出,这项游戏的最优玩法其实是随机选择出拳。排除心理因素,“石头、剪子、布”是一个简单直观的游戏,如同和计算机玩一样。然而事实上,如果对手是人或者非随机程序的话,就可以针对对手的弱点设计出更好的策略。

石头剪子布起源

#coding=utf8

import random

changes = ["", "石头", "剪子", "布"]

integral = 0

def show_changes():

    message = "\n"

    for index, value in enumerate(changes):

        if index == 0:

            continue

        message += "{0} {1}"format(index, value)

        if index != len(changes) - 1:

            message += "  "

    return message

def compute_result(_me, _ra):

    global integral

    result = "错误"

    result = "平局" if _me == _ra else result

    result = "胜利" if _me == "1" and _ra == "2" or \

                        _me == "2" and _ra == "3" or \

                         _me == "3" and _ra == "1" else result 

    result = "失败" if _me == "1" and _ra == "3" or \

                        _me == "2" and _ra == "1" or \

                         _me == "3" and _ra == "2" else result

    

    if result == "胜利":

        integral += 1

    if result == "失败":

        integral -= 1

    

    return result

def run_game():

    while 1:

        print show_changes()

        _me = str(raw_input("请出拳:")strip())

        _ra = str(randomrandint(1, len(changes) - 1))

        res = compute_result(_me, _ra)

        

        try:

            changes[int(_me)]

        except:

            print "出拳错误!"

            continue

        

        print "你出<{0}> 对方出<{1}> 本次对战<{2}> 当前积分<{3}>"format(

                                                            changes[int(_me)], 

                                                            changes[int(_ra)],

                                                            res, 

                                                            integral

                                                            )

        

        tp = raw_input("\n请选择是否退出(yes/no): ")strip()

        if tp == "no":

            continue

        elif tp == "yes":

            print "已退出 !"

        else:

            print "输入错误,已退出游戏!"

        break

print "游戏开始"

while 1:

    print 

    print ""

    print "1 开始新游戏"

    print "2 载入游戏"

    print "3 退出"

    print ""

    

    change = raw_input("请选择:")strip()

    print

    if change == "1":

        print "正在载入新游戏 "

        integral = 0

        run_game()

        print "您当前的得分是:{0}"format(integral)

    elif change == "2":

        print "正在载入 "

        run_game()

        print "您当前的得分是:{0}"format(integral)

    elif change == "3":

        break

    else:

        print "输入错误 ! 请重新输入 !"

print "游戏结束"

这可是我自己手打的 要采纳呦

有什么问题可以追问 或许我也可以教教你写代码的思路

学会了思路 你就知道怎样自己写程序了

pascal的:

var a,b:longint;

begin

read(a,b);

if (a>=1)and(a<=3)and(b>=1)and(b<=3)

then begin

if a>b then writeln('lose');

if a<b then writeln('win');

if a=b then writeln('tie');

end;

end

编写这个小游戏 我们需要几个类

1、第一个 Person 类

import javautilScanner;

/

@copyright 2018 sugarsLabcom All rights reserved

@author jingfeiwu

@date 2018年11月16日

@version 10

@ClassName Person

@description 用户类 用来计算用户输入

/

public class Person {

public static final Person me = new Person();

private int n = 0;

/

@copyright 2018 sugarsLabcom All rights reserved

@author jingfeiwu

@date 2018年11月16日

@version 10

@description 用户输入的 指令

@return

/

public int input() {

Systemoutprintln("请输入:石头,剪刀,布\n输入:@退出 退出系统");

@SuppressWarnings("resource")

Scanner scanner = new Scanner(Systemin);

String s = scannernext();

// s 里面存着 用户输入的 指令 切记这里不要使用 sequals() 而是写 "指令"equals() 这么写 是为了避免空指针

if ("石头"equals(s)) {

n = 1;

} else if ("剪刀"equals(s)) {

n = 2;

} else if ("布"equals(s)) {

n = 3;

} else if ("@退出"equals(s)) {

Systemoutprint("系统退出了");

Systemexit(0);

}

return n;

}

}

2、Computer 类

/

@copyright 2018 sugarsLabcom All rights reserved

@author jingfeiwu

@date 2018年11月16日

@version 10

@ClassName Computer

@description 游戏中电脑类 用来产生随机数

/

public class Computer {

public static final Computer me = new Computer();

/

@copyright 2018 sugarsLabcom All rights reserved

@author jingfeiwu

@date 2018年11月16日

@version 10

@description TODO

@return {int} 返回值为int 类型

/

public int random() {return (int) (Mathrandom() 3 + 1);}

}

3、Game类

/

@author jingfeiwu

@date 2018年11月16日

@version 10

@ClassName Game

@description 游戏类 用来计算游戏结果

/

public class Game {

/

@author jingfeiwu

@date 2018年11月16日

@version 10

@description 返回 人机交互结果

@param n

            {int} 用户输入 的标识 石头 为 1 剪刀 为 2 布 为 3

@param m

            {int} 电脑产生的随机数 石头 为 1 剪刀 为 2 布 为 3

/

public void result(int n, Integer m) {

String res = "";

if (mintValue() == 1)

res = "石头";

else if (mintValue() == 2)

res = "剪刀";

else

res = "布";

if (n == m) {

Systemoutprintln("平了 computer出" + res);

} else {

if (m == 1) {

if (n == 2)

Systemoutprintln("你输了 computer出 " + res);

else if (n == 3)

Systemoutprintln("你赢了 computer出 " + res);

} else if (m == 2) {

if (n == 1)

Systemoutprintln("你赢了 computer出 " + res);

else if (n == 3)

Systemoutprintln("你输了 computer出 " + res);

} else if (m == 3) {

if (n == 1)

Systemoutprintln("你输了 computer出 " + res);

else if (n == 2)

Systemoutprintln("你赢了 computer出 " + res);

}

}

}

public static void main(String[] args) {

while (true) {

Game gamer = new Game();

gamerresult(Personmeinput(), Computermerandom());

}

}

}

如下是程序运行截图

以上就是关于用1,2,3分别代表石头剪刀布,输入甲乙的猜 拳选择输出甲乙猜拳结果。(分支结构)。C语言程序设计全部的内容,包括:用1,2,3分别代表石头剪刀布,输入甲乙的猜 拳选择输出甲乙猜拳结果。(分支结构)。C语言程序设计、猜拳必胜技巧、求助,用python编写一个猜拳游戏程序,要求有这样的开头等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zz/9304007.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存