線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:3810
推到 Plurk!
推到 Facebook!

賓果問題

 
ken07042001
一般會員


發表:10
回覆:6
積分:3
註冊:2007-01-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-01-23 09:57:55 IP:61.221.xxx.xxx 訂閱
以下是我寫到一半的賓果(5*5)的程式有兩個問題想請教各位大大
1.如何計算連線
2.如何使電腦叫號不重複
麻煩各位高手幫幫我~~~想超久想不出來
//---------------------------------------------------------------------------
#include
#include
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int a1[25]={0},a2[25]={0},a3[25]={0},cpu[25]={0},player[25]={0};
int count_cpu,count_player;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
randomize();
Button3->Visible=true;

for(int i=0;i<25;i )
{
a3[i]=i 1;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
count_cpu=25;
/*
Memo1->Lines->Clear();
*/
int num_cpu;
int k=0;

for(int i=0;i<25;i )
{
a1[i]=i 1;
}

for(int i=0;i<25;i )
{
num_cpu=random(count_cpu);
cpu[i]=a1[num_cpu];


for(int j=num_cpu;j<=24;j )
{
a1[j]=a1[j 1];
}
/*
AnsiString Temp="";
for(int j=0;j<25;j )
{
Temp=Temp IntToStr(a1[j]) ";";
}
Memo1->Lines->Add("num= " IntToStr(num_cpu));
Memo1->Lines->Add(Temp);
Memo1->Lines->Add("---------------------------------------");
*/
count_cpu--;
}
for(int i=0;i<5;i )
{
for(int j=0;j<5;j )
{
StringGrid1->Cells[i][j]=IntToStr(cpu[k]);
k ;
}
}
Button1->Visible=false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
count_player=25;
int m=0;
int num_player;
for(int i=0;i<25;i )
{
a2[i]=i 1;
}
for(int i=0;i<25;i )
{
num_player=random(count_player);
player[i]=a2[num_player];
for(int j=num_player;j<24;j )
{
a2[j]=a2[j 1];
}
count_player--;
}
for(int i=0;i<5;i )
{
for(int j=0;j<5;j )
{
StringGrid2->Cells[i][j]=IntToStr(player[m]);
m ;
}
}
Button2->Visible=false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
int n=StrToInt(Edit1->Text);
int m;

for(int i=0;i<5;i )
{
for(int j=0;j<5;j )
{
if(StringGrid1->Cells[i][j]==n)
{
StringGrid1->Cells[i][j]="";
}
if(StringGrid2->Cells[i][j]==n)
{
StringGrid2->Cells[i][j]="";
}
}
}
Label3->Caption="player叫號" IntToStr(n);
Button3->Visible=false;
//----------------------------------------------
m=random(25) 1;
for(int i=0;i<5;i )
{
for(int j=0;j<5;j )
{
if(StringGrid1->Cells[i][j]==m)
{
StringGrid1->Cells[i][j]="";
}
if(StringGrid2->Cells[i][j]==m)
{
StringGrid2->Cells[i][j]="";
}
}
}
Label4->Caption="電腦叫號" IntToStr(m);
Button3->Visible=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
Edit1->Text="";
Label3->Caption="";
Label4->Caption="";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------

pcboy
版主


發表:177
回覆:1838
積分:1463
註冊:2004-01-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-01-23 13:49:05 IP:61.219.xxx.xxx 未訂閱
> 1.如何計算連線
如果剛選中的是 bango(m,n), 陣列值 1 表示被選過
if ( bango(1,n)='1' and bango(2,n)='1' and bango(3,n)='1' and bango(4,n)='1' and bango(5,n)='1' ) {
Finished=1; // 1 表示有人連成線, 遊戲結束
}

if ( bango(m,1)='1' and bango(m,2)='1' and bango(m,3)='1' and bango(m,4)='1' and bango(m,5)='1' ) {
Finished=1; // 1 表示有人連成線, 遊戲結束
}

if (m=n) {
if ( bango(1,1)='1' and bango(2,2)='1' and bango(3,3)='1' and bango(4,4)='1' and bango(5,5)='1' ) {
Finished=1; // 1 表示有人連成線, 遊戲結束
}
}

if (m n=6) {
if ( bango(1,5)='1' and bango(2,4)='1' and bango(3,3)='1' and bango(4,2)='1' and bango(5,1)='1' ) {
Finished=1; // 1 表示有人連成線, 遊戲結束
}
}

> 2.如何使電腦叫號不重複
用陣列 choose(5,5) 紀錄叫過的號碼

------
能力不足,求助於人;有能力時,幫幫別人;如果您滿意答覆,請適時結案!

子曰:問有三種,不懂則問,雖懂有疑則問,雖懂而想知更多則問!
ChungLin.Net
中階會員


發表:2
回覆:33
積分:52
註冊:2006-07-26

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-01-23 14:08:54 IP:59.120.xxx.xxx 訂閱
你好,以下是以前小弟在 VB 上寫的想法
使用struct 的方式來記錄一個數字的動作

typedef struct {
int Number;
bool Selected;
} BINGO


用這樣的方式,可以判別該數字是否已經選取過
就可以避開重覆的問題,另外連線的方式也就可
以處理,以下一個小範例
BINGO A[25];
int ColCount=0; // 橫向
int RowCount=0; // 直向
int XCountA=0; // X 向 左上至右下
int XCountB=0; // X 向 右上至左下
for(int i=0;i<5;i ) {
for(int j=0;j<5;j ) {
// 判別橫向
if(A[j i*5].Selected)
ColCount ;
// 判別直向
if()
RowCount ;
// 判別X向
if()
XCountA ;
if()
XCountB ;
}
// 當值為 5 表示已連線
if(ColCount == 5)
iLine ;
if(RowCount == 5)
iLine ;
if(XCountA == 5)
iLine ;
if(XCountB == 5)
iLine ;
ColCount = 0;
RowCount = 0;
XCountA = 0;
XCountB = 0;
}
if( iLine >=5 )
printf("BINGO!");



------
無限的想像,無盡的延伸。
syntax
尊榮會員


發表:26
回覆:1139
積分:1258
註冊:2002-04-23

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-03-03 17:37:14 IP:61.64.xxx.xxx 訂閱
計算連線,可以更簡化

將三欄加起來,除以第一欄,整除,就是都相同,自然成一線囉
做 8 次
為何做 8 次,恩,不是有 8 種連線方式嗎?


===================引 用 文 章===================
> 1.如何計算連線
如果剛選中的是 bango(m,n), 陣列值 1 表示被選過
if ( bango(1,n)='1' and bango(2,n)='1' and bango(3,n)='1' and bango(4,n)='1' and bango(5,n)='1' ) {
Finished=1;// 1 表示有人連成線, 遊戲結束
}

if ( bango(m,1)='1' and bango(m,2)='1' and bango(m,3)='1' and bango(m,4)='1' and bango(m,5)='1' ) {
Finished=1;// 1 表示有人連成線, 遊戲結束
}

if (m=n) {
if ( bango(1,1)='1' and bango(2,2)='1' and bango(3,3)='1' and bango(4,4)='1' and bango(5,5)='1' ) {
Finished=1;// 1 表示有人連成線, 遊戲結束
}
}

if (m n=6) {
if ( bango(1,5)='1' and bango(2,4)='1' and bango(3,3)='1' and bango(4,2)='1' and bango(5,1)='1' ) {
Finished=1;// 1 表示有人連成線, 遊戲結束
}
}

> 2.如何使電腦叫號不重複
用陣列 choose(5,5) 紀錄叫過的號碼

暗黑破壞神
版主


發表:9
回覆:2301
積分:1627
註冊:2004-10-04

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-03-03 20:04:21 IP:218.170.xxx.xxx 訂閱
如果你懶得去做演算法。
手工做一下TABLE。
把所有的組合都做出來。你也可以用比對法。
這個方法笨是笨。對現在的PC來說。運算起來也不是太大的負擔了。
系統時間:2024-03-29 3:20:13
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!