我正在尝试在Asp.net 2.0(VB)中创建一个典型的Housie / Bingo游戏票。但是,没有成功。票证包含3行,9列。总共27个区块,它必须只有15个应该填写那些27.并且每列包含的值如第1列应该在1-10和2之间必须具有11-20之间的随机值..无关紧要有多少每列中填充的块.1是必须的,没有单个列应该是空白的,所有9列必须填充,一些填充所有3个块,一些有1个,总共15个块填充整个票。随机数..
这里的家伙是典型的房车票规格..请帮我生成这样的票。我已经尝试了,但是没有那么多成功,我将整个列留空并验证列..在系统上需要额外的负载。请找到我的方法。
答案 0 :(得分:3)
首先重新定义您的要求:
我就是这样做的:
selectNums
)并删除在步骤1中选择的所有数据selectNums
数组selectNums
aray selectNums
数组中删除该范围内的所有数字。该算法将在循环中完全采用9步+6步,因此它具有确定性,对处理器利用率更好。它还可以为每张专栏填写最多3个数字并且不少于1个(如果我理解您的要求,那么由于问题中的英语太差)。
当您选择随机数时,您总是选择0到selectNums
数组长度之间的数字,这将为您提供数组中您必须从中获取数字的位置。
以上步骤将使您获得正好15个数字,其中最多3个来自相同的10个数字范围。精细。您现在要做的就是创建机票。
row1Count
,row2Count
和row3Count
并将它们全部设为0。selectNums
数组中删除这些数字。selectNums
数组selectNums
数组中获取第一个数字,并将其放入计数最小的行中,并将其放入该特定行的故障单中。当至少有两行具有相同的计数时,您可以通过随机选择一个或选择第一个(最快)来选择您喜欢的任何一个。selectNums
数组这部分应该可以让你获得一张完整的票证,其中所有列都至少包含一个数字,所有行总共包含5个数字。
如果不允许较小的数字在较大的数字下,您可以随时在此过程中添加一个额外的步骤,并对那些只有一个数字的列中的数字重新排序。
使用数组和计数器简化了此解决方案。您当然可以创建一个功能丰富的完整对象模型,并为您提供所需的所有信息。例如,您可以拥有Ticket和TicketColumn类:
public class TicketColumn
{
public int Count { get; }
public int? FirstRowValue { get; set; }
public int? SecondRowValue { get; set; }
public int? ThirdRowValue { get; set; }
...
public void Reorder() { ... }
}
public class Ticket
{
public TicketColumn[] Columns
public int FirstRowCount { get; private set; }
public int SecondRowCount { get; private set; }
public int ThirdRowCount { get; private set; }
...
}
或类似的东西。这只是一个想法,这个整个程序将以面向对象的方式更好。
答案 1 :(得分:0)
我准备了一个代码,用于与任意数量的玩家一起玩Housie。它会告知是否有人赢得了比赛,并在有人赢得满堂比赛时终止
解决此问题的方法如下: 我准备了10张清单。每个列表具有3个唯一的随机数,这些随机数按升序排列,范围从10到20、20到30,...,80到90。接下来,我将5个随机列表中的第一个数字分配给第一行,第二个另一个5个随机列表中的第一个数字显示在中间一行,另外5个随机列表中的第三个数字显示在最后一行。我这样做的目的是不重复数字,确保在票证的每一行上仅打印5个数字,每列从上到下以升序排列它的数字
我在没有数字可打印的地方使用了空字符串'',并且在星号/星号'*'标记处告诉玩家他/她已经在该票证上标记了该数字!
这是一张样票;
<player name>, your ticket is as follows:-
[' ' ' ' ' ' '33' ' ' '54' '66' '72' '83']
[' ' '12' '27' ' ' '45' '57' ' ' ' ' '88']
['8' '19' '29' ' ' '49' ' ' ' ' '75' ' ']
<player name>, do you want to mark?(Type 'Yes' or 'No'):
然后我问玩家是否要标记。然后,我确保玩家输入票证中存在的整数,并且该整数也称为
看起来像这样(标记后);
The lucky number is 54!
<player name>, your ticket is as follows:-
[' ' ' ' ' ' '33' ' ' '54' '66' '72' '83']
[' ' '12' '27' ' ' '45' '57' ' ' ' ' '88']
['8' '19' '29' ' ' '49' ' ' ' ' '75' ' ']
<player name>, do you want to mark?(Type 'Yes' or 'No'): Yes
<player name>, type the number you want to mark: 54
<player name>, your ticket is as follows:-
[' ' ' ' ' ' '33' ' ' '*54' '66' '72' '83']
[' ' '12' '27' ' ' '45' '57' ' ' ' ' '88']
['8' '19' '29' ' ' '49' ' ' ' ' '75' ' ']
请注意,整数54旁边有一个星号。
然后询问用户是否要检查他/她是否赢了! 有关获奖者的确认信息如下;
<player name>, do you want to check if you have won?(Type 'Yes' or 'No'): Yes
Sorry <player name>, you have not won!
Jaldi 5 Winner: None
Top row winner: None
Middle row winner: None
Bottom row winner: None
Full house winner: None
我确保所叫的数字不会重复(主板是一个数字范围为1到90的列表,每次将一个称为sam的随机数从主板上删除,而玩家如果有机会进行标记,则代码可确保玩家的门票中存在该数字,而主板中则是不的数字。如果玩家输入的数字不满足上述要求提到的条件,它会不断询问直到玩家输入正确的数字
此代码的特色在于它可以接受任意数量的玩家。它首先询问您玩游戏的玩家数量,然后询问多次每个玩家的姓名
最后,当玩家赢得满满的房子时,代码会自动终止
这是我准备的代码;
import random
import numpy as np
def list_of_ten(lower_limit, upper_limit):
yield list(str(number) for number in range(lower_limit, upper_limit))
def replace(numbers_list, row, collection):
for element in numbers_list:
if len(element) == 1:
collection[row][0] = element
elif int(element) == 90:
collection[row][-1] = element
else:
collection[row][int(element[0])] = element
def check_number(number, array):
row_counter = 0
column_counter = 0
for row in array:
if number in row:
for element in row:
if element == number:
return True, tuple((row_counter, column_counter))
column_counter += 1
row_counter += 1
else:
return False, None
def class_instantiation(player_count, class_to_create):
names_dict = dict()
counter = 0
while counter < int(player_count):
temporaray_input = input(f"Enter the name of the player{counter + 1}: ")
names_dict[temporaray_input.lower()] = class_to_create(temporaray_input)
counter += 1
return names_dict
def call_method(diction):
for tup in diction.items():
diction[tup[0]].display_ticket()
diction[tup[0]].mark()
def call_numeral(diction):
for tup in diction.items():
return diction[tup[0]].call_number()
class Player:
board = list(range(1, 91))
jaldi_5_winner = None
top_row_winner = None
middle_row_winner = None
bottom_row_winner = None
full_house_winner = None
def __init__(self, name):
self.name = name
self.full_list = list()
self.check_top = list()
self.check_middle = list()
self.check_bottom = list()
n1 = random.sample(next(list_of_ten( 1, 10)), 3)
n2 = random.sample(next(list_of_ten(10, 20)), 3)
n3 = random.sample(next(list_of_ten(20, 30)), 3)
n4 = random.sample(next(list_of_ten(30, 40)), 3)
n5 = random.sample(next(list_of_ten(40, 50)), 3)
n6 = random.sample(next(list_of_ten(50, 60)), 3)
n7 = random.sample(next(list_of_ten(60, 70)), 3)
n8 = random.sample(next(list_of_ten(70, 80)), 3)
n9 = random.sample(next(list_of_ten(80, 91)), 3)
n1.sort()
n2.sort()
n3.sort()
n4.sort()
n5.sort()
n6.sort()
n7.sort()
n8.sort()
n9.sort()
number_list = [n1, n2, n3, n4, n5, n6, n7, n8, n9]
self.ticket = np.array([[' '] * 9] * 3)
self.top_row = [element[0] for element in random.sample(number_list, 5)]
self.middle_row = [element[1] for element in random.sample(number_list, 5)]
self.bottom_row = [element[2] for element in random.sample(number_list, 5)]
replace(self.top_row, 0, self.ticket)
replace(self.middle_row, 1, self.ticket)
replace(self.bottom_row, 2, self.ticket)
def display_ticket(self):
print("\n\n" + f"{self.name}, your ticket is as follows:-" + "\n")
print(self.ticket[0])
print(self.ticket[1])
print(self.ticket[2])
def call_number(self):
print(f"The lucky number is {Player.board.pop(Player.board.index(random.choice(Player.board)))}!")
def mark(self):
mark_it = input("\n" + f"{self.name}, do you want to mark?(Type 'Yes' or 'No'): ")
while not mark_it.lower() == 'yes' and not mark_it.lower() == 'no':
mark_it = input("\n" + f"{self.name}, please type 'Yes' or 'No' only: ")
if mark_it.lower() == 'yes':
mark_number = input("\n" + f"{self.name}, type the number you want to mark: " + " ")
condition = check_number(mark_number, self.ticket)
while not condition[0] or int(mark_number) in Player.board:
mark_number = input("\n" + "Type a number present in your ticket which has also been called: ")
condition = check_number(mark_number, self.ticket)
if mark_number in self.ticket[0]:
self.check_top.append(mark_number)
self.full_list.append(mark_number)
elif mark_number in self.ticket[1]:
self.check_middle.append(mark_number)
self.full_list.append(mark_number)
else:
self.check_bottom.append(mark_number)
self.full_list.append(mark_number)
self.ticket[condition[1][0]][condition[1][1]] = "*" + mark_number
self.display_ticket()
winner_input = input("\n" + f"{self.name}, do you want to check if you have won?(Type 'Yes' or 'No'): ")
while not winner_input.lower() == 'yes' and not winner_input.lower() == 'no':
winner_input = input("\n" + f"{self.name}, please type 'Yes' or 'No' only: ")
if winner_input.lower() == 'yes':
if len(self.full_list) == 5 and Player.jaldi_5_winner == None:
print("\n" + f"{self.name}, you have won jaldi 5!" + "\n")
Player.jaldi_5_winner = self.name
elif len(self.full_list) == 15 and Player.full_house_winner == None:
print("\n" + f"Congratulations, {self.name}, you have won the game!" + "\n")
Player.full_house_winner = self.name
elif len(self.check_top) == 5 and Player.top_row_winner == None:
print("\n" + f"{self.name}, you have won the top row!" + "\n")
Player.top_row_winner = self.name
elif len(self.check_middle) == 5 and Player.middle_row_winner == None:
print("\n" + f"{self.name}, you have won the middle row!" + "\n")
Player.middle_row_winner = self.name
elif len(self.check_bottom) == 5 and Player.bottom_row_winner == None:
print("\n" + f"{self.name}, you have won the bottom row!" + "\n")
Player.bottom_row_winner = self.name
else:
print("\n" + f"Sorry {self.name}, you have not won!" + "\n")
print(f" Jaldi 5 Winner: {Player.jaldi_5_winner} ")
print(f" Top row winner: {Player.top_row_winner} ")
print(f"Middle row winner: {Player.middle_row_winner}")
print(f"Bottom row winner: {Player.bottom_row_winner}")
print(f"Full house winner: {Player.full_house_winner}")
no_of_players = input("How many players are going to play housie?: ")
players_dict = class_instantiation(no_of_players, Player)
while True:
if Player.full_house_winner != None:
break
else:
call_numeral(players_dict)
call_method(players_dict)
答案 2 :(得分:-1)
$arr = new SplFixedArray(27);
for($m=1;$m<=100000;$m++)
{
in:
$final_array = array();
foreach ( $arr as $key => $val )
$final_array[ $key+1 ] = $val;
$elements_array=array();
foreach ( $arr as $key => $val )
$elements_array[ $key+1 ] = $val;
for($i=1;$i<=count($elements_array);$i++)
{
if($i==1 || $i==10 || $i==19 )
{
$elements_array[$i]=rand(1,9);
}
if($i==2 || $i==11 || $i==20 )
{
$elements_array[$i]=rand(10,19);
}
if($i==3 || $i==12 || $i==21 )
{
$elements_array[$i]=rand(20,29);
}
if($i==4 || $i==13 || $i==22 )
{
$elements_array[$i]=rand(30,39);
}
if($i==5 || $i==14 || $i==23 )
{
$elements_array[$i]=rand(40,49);
}
if($i==6 || $i==15 ||$i==24 )
{
$elements_array[$i]=rand(50,59);
}
if($i==7 || $i==16 ||$i==25 )
{
$elements_array[$i]=rand(60,69);
}
if($i==8 || $i==17 || $i==26 )
{
$elements_array[$i]=rand(70,79);
}
if($i==9 || $i==18 || $i==27)
{
$elements_array[$i]=rand(80,90);
}
}
for($k=1;$k<=5;$k++)
{
$index1=rand(1,9);
$final_array[$index1]=$elements_array[$index1];
}
$x1 = 0;
$ar1=[];
for($q=1;$q<=9;$q++)
{
if(isset($final_array[$q]))
{
$ar1[$x1]= $q;
$x1++;
}
}
loop:
if($x1 != 5)
{
$in1 =rand(1,9);
if(!in_array($in1, array_keys($ar1)))
{
$final_array[$in1]=$elements_array[$in1];
$ar[$x1]= $in1;
$x1++;
}
goto loop;
}
$z1=0;
for($q=1;$q<=9;$q++)
{
if(isset($final_array[$q]))
{
$ar1[$x1]= $q;
$z1++;
}
}
if($z1 != 5)
goto in;
for($l=1;$l<=5;$l++)
{
$index2=rand(10,18);
$final_array[$index2]=$elements_array[$index2];
}
$x2 = 0;
$ar2=[];
for($q=10;$q<=18;$q++)
{
if(isset($final_array[$q]))
{
$ar2[$x2]= $q;
$x2++;
}
}
loop2:
if($x2 != 5)
{
$in2 =rand(10,18);
if(!in_array($in2, array_keys($ar2)))
{
$final_array[$in2]=$elements_array[$in2];
$ar[$x2]= $in2;
$x2++;
}
goto loop2;
}
$z2=0;
for($q=10;$q<=18;$q++)
{
if(isset($final_array[$q]))
{
$ar1[$x1]= $q;
$z2++;
}
}
if($z2 != 5)
goto in;
for($n=1;$n<=5;$n++)
{
$index3=rand(19,27);
$final_array[$index3]=$elements_array[$index3];
}
$x3 = 0;
$ar3=[];
for($q=19;$q<=27;$q++)
{
if(isset($final_array[$q]))
{
$ar3[$x3]= $q;
$x3++;
}
}
loop3:
if($x3 != 5)
{
$in3 =rand(19,27);
if(!in_array($in3, array_keys($ar3)))
{
$final_array[$in3]=$elements_array[$in3];
$ar[$x3]= $in3;
$x3++;
}
goto loop3;
}
$z3=0;
for($q=19;$q<=27;$q++)
{
if(isset($final_array[$q]))
{
$ar3[$x3]= $q;
$z3++;
}
}
if($z3 != 5)
goto in;
DB::table('tambola')->insert(['a1'=>$final_array[1],
'a2'=>$final_array[2],
'a3'=>$final_array[3],
'a4'=>$final_array[4],
'a5'=>$final_array[5],
'a6'=>$final_array[6],
'a7'=>$final_array[7],
'a8'=>$final_array[8],
'a9'=>$final_array[9],
'b1'=>$final_array[10],
'b2'=>$final_array[11],
'b3'=>$final_array[12],
'b4'=>$final_array[13],
'b5'=>$final_array[14],
'b6'=>$final_array[15],
'b7'=>$final_array[16],
'b8'=>$final_array[17],
'b9'=>$final_array[18],
'c1'=>$final_array[19],
'c2'=>$final_array[20],
'c3'=>$final_array[21],
'c4'=>$final_array[22],
'c5'=>$final_array[23],
'c6'=>$final_array[24],
'c7'=>$final_array[25],
'c8'=>$final_array[26],
'c9'=>$final_array[27],
]);
}