Skip to content

Instantly share code, notes, and snippets.

@zclongpop123
Last active August 29, 2019 06:00
Show Gist options
  • Save zclongpop123/522a9a227b0cf02452af71c77092bb47 to your computer and use it in GitHub Desktop.
Save zclongpop123/522a9a227b0cf02452af71c77092bb47 to your computer and use it in GitHub Desktop.
剪子包袱锤
# coding: utf-8
#========================================
# author: Changlong.Zang
# mail: zclongpop123@163.com
# time: Wed Aug 28 17:38:51 2019
#========================================
import math, random
#--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
#- 通过计算角度正弦值
data = {
0: u'剪子',
120: u'包袱',
240: u'锤子'
}
def game(you, computer):
'''
'''
if you == computer:
return u'平局'
elif round(math.sin((you + 120) / 180.0 * math.pi), 3) == round(math.sin(computer / 180.0 * math.pi), 3):
return u'你赢了'
else:
return u'你输了'
#- 通过计算余数
data = {
0: u'剪子',
1: u'包袱',
2: u'锤子'
}
def game(you, computer):
'''
'''
if you == computer:
return u'平局'
elif (you + 1) % 3 == computer:
return u'你赢了'
else:
return u'你输了'
#- 通过二进制退位运算
data = {
4: u'剪子',
2: u'包袱',
1: u'锤子',
}
def game(you, computer):
'''
'''
if you == computer:
return u'平局'
elif (you >> 1 or 4) == computer:
return u'你赢了'
else:
return u'你输了'
#- 通过移动列表元素
data = {
0: u'剪子',
1: u'包袱',
2: u'锤子'
}
def game(you, computer):
'''
'''
if you == computer:
return u'平局'
you_list = [0, 0, 0]
computer_list = [0, 0, 0]
you_list[you] = 1
computer_list[computer] = 1
you_list.insert(0, you_list.pop())
if you_list == computer_list:
return u'你赢了'
else:
return u'你输了'
#- 与列表类似,通过矩阵平移
import numpy
data = {
0: u'剪子',
1: u'包袱',
2: u'锤子'
}
def game(you, computer):
'''
'''
if you == computer:
return u'平局'
array = numpy.zeros(6).reshape(2, 3)
array[0][you] = 1
array[1][computer] = 1
array[0] = numpy.roll(array[0], 1)
if numpy.all(array[0] == array[1]):
return u'你赢了'
else:
return u'你输了'
#- 通过计算24小时内的三个平均小时点
import datetime
data = {
0: u'剪子',
8: u'包袱',
16: u'锤子'
}
def game(you, computer):
'''
'''
if you == computer:
return u'平局'
next_time = datetime.datetime(1970, 1, 1) + datetime.timedelta(hours=you) + datetime.timedelta(hours=8)
if next_time.hour == computer:
return u'你赢了'
else:
return u'你输了'
@DavidYoung93
Copy link

长龙大大6666

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment