Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {Made by TVA}
- Program Project_Bingo_Artifical_Intelligence;
- Uses crt;
- Var
- Human_Board, COM_Board: Array [1..5,1..5] of Integer;
- i, j: Integer;
- Mode: String;
- Procedure Pout(S: String); {Pascal Output - Insipired by Cout (C++) by Stroup}
- Begin
- Writeln(S);
- Delay(1000);
- End;
- Procedure Info;
- Begin
- Pout('Made by T.V.A');
- Pout('Do not copy');
- End;
- Procedure SwapHuman(x, y, i, j: Integer);
- Var
- Mid: Integer;
- Begin
- Mid:=Human_Board[x,y];
- Human_Board[x,y]:=Human_Board[i,j];
- HUman_Board[i,j]:=Mid;
- End;
- Procedure Print_Human_Board;
- Var
- x, y: Integer;
- Begin
- TextColor(White);
- For x:=1 to 5 do
- Begin
- For y:=1 to 5 do
- If Human_Board[x,y]=0 then
- Begin
- TextColor(Yellow);
- Write(Human_Board[x,y]:3);
- TextColor(White);
- End
- else
- Write(Human_Board[x,y]:3);
- Writeln;
- End;
- End;
- Procedure Print_COM_Board;
- Var
- x, y: Integer;
- Begin
- TextColor(White);
- For x:=1 to 5 do
- Begin
- For y:=1 to 5 do
- If COM_Board[x,y]=0 then
- Begin
- TextColor(Yellow);
- Write(COM_Board[x,y]:3);
- TextColor(White);
- End
- else
- Write(COM_Board[x,y]:3);
- Writeln;
- End;
- End;
- Function Valid(value, PosX, PosY: Integer): Boolean;
- Var
- i, j, count: Integer;
- Bo: Boolean;
- Begin
- count:=0; Bo:=true;
- For i:=1 to 5 do
- For j:=1 to 5 do
- If (value=Human_Board[i,j]) and ((i<>PosX) or (j<>PosY)) then inc(count);
- If count<>0 then Bo:=false
- else Bo:=true;
- If (value<=0) or (value>25) then Bo:=false
- else Bo:=true;
- Valid:=Bo;
- End;
- Procedure Init_Board;
- Var
- x, y, i, pt, SwapX, SwapY: Integer;
- Choice: String;
- Begin
- Write('Choose mode: ');
- Readln(Mode);
- For i:=1 to length(Mode) do
- Mode[i]:=Upcase(Mode[i]);
- While (Mode<>'EASY') and (Mode<>'NORMAL') do
- Begin
- Writeln('Mode inputed is invalid, please input again: ');
- Readln(Mode);
- For i:=1 to length(Mode) do
- Mode[i]:=Upcase(Mode[i]);
- End;
- Write('Make board bay manual or auto? ');
- Readln(Choice);
- For i:=1 to length(Choice) do
- Choice[i]:=Upcase(Choice[i]);
- While (Choice='INFO') do
- Begin
- Info;
- Writeln('Input command again: ');
- Readln(Choice);
- End;
- While (Choice<>'AUTO') and (Choice<>'MANUAL') and (Choice<>'INFO') do
- Begin
- Write('Input command again: ');
- Readln(Choice);
- For i:=1 to length(Choice) do
- Choice[i]:=Upcase(Choice[i]);
- End;
- If Choice='AUTO' then
- Begin
- pt:=0;
- For x:=1 to 5 do
- For y:=1 to 5 do
- Begin
- inc(pt);
- Human_Board[x,y]:=pt;
- End;
- Randomize;
- For x:=1 to 5 do
- For y:=1 to 5 do
- Begin
- SwapX:=Random(5)+1;
- SwapY:=Random(5)+1;
- SwapHuman(x,y,SwapX,SwapY);
- End;
- End
- else
- For x:=1 to 5 do
- For y:=1 to 5 do
- Begin
- Write('Input &Human_Board[',x,',',y,']= ');
- Readln(Human_Board[x,y]);
- While Not(Valid(Human_Board[x,y],x,y)) do
- Begin
- Writeln('Data Inputed is invalid!!!!');
- Write('Input again pls (you dumb ass): ');
- Readln(Human_Board[x,y]);
- End;
- End;
- End;
- Procedure SwapCOM(x, y, i, j: Integer);
- Var
- Mid: Integer;
- Begin
- Mid:=COM_Board[x,y];
- COM_Board[x,y]:=COM_Board[i,j];
- COM_Board[i,j]:=Mid;
- {}
- {Alternative Data}
- {}
- {COM_Board[x,y]:=COM_Board[x,y]+COM_Board[i,j];
- COM_Board[i,j]:=COM_Board[x,y]-COM_Board[i,j];
- COM_Board[x,y]:=COM_Board[i,j]-COM_Board[i,j]}
- {
- 3 4
- 7 4
- 7 3
- 4 3
- }
- End;
- Procedure Init_COM_Board;
- Var
- x, y, SwapX, SwapY, pt: Integer;
- Begin
- pt:=0;
- For x:=1 to 5 do
- For y:=1 to 5 do
- Begin
- inc(pt);
- COM_Board[x,y]:=pt;
- End;
- For x:=1 to 5 do
- For y:=1 to 5 do
- Begin
- SwapX:=Random(5)+1;
- SwapY:=Random(5)+1;
- SwapCOM(x,y,SwapX,SwapY);
- End;
- End;
- Procedure COMWon_HumanLost;
- Begin
- clrscr;
- Writeln('AI Won');
- Delay(500);
- Print_Human_Board;
- Writeln;
- Print_COM_Board;
- Readln;
- Halt;
- End;
- Procedure HumanWon_COMLost;
- Begin
- clrscr;
- Writeln('Human Won');
- Delay(500);
- Print_Human_Board;
- Writeln;
- Print_COM_Board;
- Readln;
- Halt;
- End;
- Procedure Tie;
- Begin
- clrscr;
- Writeln('It''s a tie');
- Delay(500);
- Print_Human_Board;
- Writeln;
- Print_COM_Board;
- Readln;
- Halt;
- End;
- Function COMDiagonal: Integer;
- Var
- i, count, c: Integer;
- Begin
- c:=0; count:=0;
- For i:=1 to 5 do
- If COM_Board[i,i]=0 then
- inc(count);
- If count=5 then inc(c);
- count:=0;
- For i:=i to 5 do
- If COM_Board[i,5-i+1]=0 then
- inc(count);
- If count=5 then inc(c);
- COMDiagonal:=c;
- End;
- Function Diagonal: Integer;
- Var
- i, count, c: Integer;
- Begin
- c:=0; count:=0;
- For i:=1 to 5 do
- If Human_Board[i,i]=0 then
- inc(count);
- If count=5 then inc(c);
- count:=0;
- For i:=i to 5 do
- If Human_Board[i,5-i+1]=0 then
- inc(count);
- If count=5 then inc(c);
- Diagonal:=c;
- End;
- Function COMRowScore: Integer;
- Var
- i, j, count, c: Integer;
- Begin
- c:=0;
- For i:=1 to 5 do
- Begin
- count:=0;
- For j:=1 to 5 do
- If COM_Board[i,j]=0 then inc(count);
- If count=5 then inc(c);
- End;
- COMRowScore:=c;
- End;
- Function HumanRowScore: Integer;
- Var
- i, j, count, c: Integer;
- Begin
- c:=0;
- For i:=1 to 5 do
- Begin
- count:=0;
- For j:=1 to 5 do
- If Human_Board[i,j]=0 then inc(count);
- If count=5 then inc(c);
- End;
- HumanRowScore:=c;
- End;
- Function HumanColumnScore: Integer;
- Var
- i, j, count, c: Integer;
- Begin
- c:=0;
- For i:=1 to 5 do
- Begin
- count:=0;
- For j:=1 to 5 do
- If Human_Board[j,i]=0 then inc(count);
- If count=5 then inc(c);
- End;
- HumanColumnScore:=c;
- End;
- Function COMColumnScore: Integer;
- Var
- i, j, count, c: Integer;
- Begin
- c:=0;
- For i:=1 to 5 do
- Begin
- count:=0;
- For j:=1 to 5 do
- If COM_Board[j,i]=0 then inc(count);
- If count=5 then inc(c);
- End;
- COMColumnScore:=c;
- End;
- Function COMVictoryCondition: Boolean;
- Var
- Bo: Boolean;
- Begin
- If COMColumnScore+COMRowScore+COMDiagonal>=5 then Bo:=True
- else Bo:=false;
- COMVictoryCondition:=Bo;
- End;
- Function HumanVictoryCondition: Boolean;
- Var
- Bo: Boolean;
- Begin
- If HumanColumnScore+HumanRowScore+Diagonal>=5 then Bo:=True
- else Bo:=false;
- HumanVictoryCondition:=Bo;
- End;
- Function ValidChoice(value: Integer): Boolean;
- Var
- i, j, count: Integer;
- Bo: Boolean;
- Begin
- count:=0;
- For i:=1 to 5 do
- For j:=1 to 5 do
- If Human_Board[i,j]=value then inc(count);
- If count=0 then Bo:=false
- else Bo:=true;
- ValidChoice:=Bo;
- End;
- Procedure Human_Pick;
- Var
- Pick, i, j: Integer;
- Begin
- Write('Input choice: ');
- Readln(Pick);
- While Not(ValidChoice(Pick)) or (Pick<=0) or (Pick>25) do
- Begin
- clrscr;
- Print_Human_Board;
- Writeln;
- Print_COM_Board;
- Writeln('Data inputed is invalid!!!');
- Write('Input again: ');
- Readln(Pick);
- End;
- For i:=1 to 5 do
- For j:=1 to 5 do
- If Human_Board[i,j]=Pick then Human_Board[i,j]:=0;
- For i:=1 to 5 do
- For j:=1 to 5 do
- If COM_Board[i,j]=Pick then COM_Board[i,j]:=0;
- End;
- Function ValidCOMChoice(value: Integer): Boolean;
- Var
- count, i, j: Integer;
- Bo: Boolean;
- Begin
- count:=0;
- For i:=1 to 5 do
- For j:=1 to 5 do
- If COM_Board[i,j]=value then inc(count);
- If count=0 then Bo:=false
- else Bo:=true;
- ValidCOMChoice:=Bo;
- End;
- Function GetDiagonal: Integer;
- Var
- i, j, Dia, Dia2: Integer;
- Begin
- Dia:=0; Dia2:=0;
- For i:=1 to 5 do
- Begin
- If COM_Board[i,i]=0 then inc(Dia);
- If COM_Board[i,5-i+1]=0 then inc(Dia2);
- End;
- If Dia>=Dia2 then
- GetDiagonal:=Dia
- else GetDiagonal:=Dia2;
- End;
- Function GetPosOfMaxDiagonal: Integer;
- Var
- i, j, Dia, Dia2: Integer;
- Begin
- Dia:=0; Dia2:=0;
- For i:=1 to 5 do
- Begin
- If COM_Board[i,i]=0 then inc(Dia);
- If COM_Board[i,5-i+1]=0 then inc(Dia2);
- End;
- If Dia>=Dia2 then
- GetPosOfMaxDiagonal:=1
- else GetPosOfMaxDiagonal:=2;
- End;
- Function GetRow: Integer;
- Var
- i, j, count, Max: Integer;
- Begin
- Max:=-MaxInt;
- For i:=1 to 5 do
- Begin
- count:=0;
- For j:=1 to 5 do
- If COM_Board[i,j]=0 then inc(count);
- If count>Max then
- Max:=count;
- End;
- GetRow:=Max;
- End;
- Function GetPosOfMaxRow: Integer;
- Var
- i, j, count, Max, Pos: Integer;
- Begin
- Max:=-MaxInt;
- For i:=1 to 5 do
- Begin
- count:=0;
- For j:=1 to 5 do
- If COM_Board[i,j]=0 then inc(count);
- If count>Max then
- Begin
- Max:=count;
- Pos:=i;
- End;
- End;
- GetPosOfMaxRow:=Pos;
- End;
- Function GetColumn: Integer;
- Var
- i, j, count, Max: Integer;
- Begin
- Max:=-MaxInt;
- For i:=1 to 5 do
- Begin
- count:=0;
- For j:=1 to 5 do
- If COM_Board[j,i]=0 then inc(count);
- If count>Max then
- Max:=count;
- End;
- GetColumn:=Max;
- End;
- Function GetPosOfMaxColumn: Integer;
- Var
- i, j, count, Max, Pos: Integer;
- Begin
- Max:=-MaxInt;
- For i:=1 to 5 do
- Begin
- count:=0;
- For j:=1 to 5 do
- If COM_Board[j,i]=0 then inc(count);
- If count>Max then
- Begin
- Max:=count;
- Pos:=i;
- End;
- End;
- GetPosOfMaxColumn:=Pos;
- End;
- Procedure COM_Smart_Pick;
- Var
- MaxRow, MaxColumn, MaxDiagonal: Integer;
- PosRow, PosColumn, PosDiagonal: Integer;
- Pick: Integer;
- Begin
- MaxRow:=GetRow;
- MaxColumn:=GetColumn;
- MaxDiagonal:=GetDiagonal;
- If MaxRow>=MaxColumn then
- If MaxRow>=MaxDiagonal then
- Begin
- PosRow:=GetPosOfMaxrow;
- For i:=1 to 5 do
- If COM_Board[PosRow,i]<>0 then
- Begin
- Pick:=COM_Board[PosRow,i];
- Break;
- End;
- End
- else
- Begin
- PosDiagonal:=GetPosofMaxDiagonal;
- If PosDiagonal=1 then
- Begin
- For i:=1 to 5 do
- If COM_Board[i,i]<>0 then
- Begin
- Pick:=COM_Board[i,i];
- Break;
- End;
- End
- else
- Begin
- For i:=1 to 5 do
- If COM_Board[i,5-i+1]<>0 then
- Begin
- Pick:=COM_Board[i,5-i+1];
- Break;
- End;
- End;
- End
- else
- If MaxColumn>=MaxDiagonal then
- Begin
- PosColumn:=GetPosOfMaxColumn;
- For i:=1 to 5 do
- If COM_Board[i,PosColumn]<>0 then
- Begin
- Pick:=COM_Board[i,PosColumn];
- Break;
- End;
- End
- else
- Begin
- PosDiagonal:=GetPosOfMaxDiagonal;
- If PosDiagonal=1 then
- Begin
- For i:=1 to 5 do
- If COM_Board[i,i]<>0 then
- Begin
- Pick:=COM_Board[i,i];
- Break;
- End;
- End
- else
- Begin
- For i:=1 to 5 do
- If COM_Board[i,5-i+1]<>0 then
- Begin
- Pick:=COM_Board[i,5-i+1];
- Break;
- End;
- End;
- End;
- For i:=1 to 5 do
- For j:=1 to 5 do
- If Pick=COM_Board[i,j] then COM_Board[i,j]:=0;
- For i:=1 to 5 do
- For j:=1 to 5 do
- If Pick=Human_Board[i,j] then Human_Board[i,j]:=0;
- End;
- Procedure COM_God_Pick;
- Begin
- End;
- Procedure COM_Random_Pick;
- Var
- Pick, i, j: Integer;
- Begin
- Pick:=Random(24)+1;
- While Not(ValidCOMChoice(Pick)) do
- Pick:=Random(24)+1;
- For i:=1 to 5 do
- For j:=1 to 5 do
- If COM_Board[i,j]=Pick then COM_Board[i,j]:=0;
- For i:=1 to 5 do
- For j:=1 to 5 do
- If Human_Board[i,j]=Pick then Human_Board[i,j]:=0;
- End;
- Procedure Play;
- Begin
- While True Do
- Begin
- clrscr;
- Print_Human_Board;
- Writeln;
- Print_COM_Board;
- Human_Pick;
- If (HumanVictoryCondition) and (COMVictoryCondition) then Tie
- else
- Begin
- If (HumanVictoryCondition) then HumanWon_COMLost;
- If (COMVictoryCondition) then COMWon_HumanLost;
- End;
- clrscr;
- Print_Human_Board;
- Writeln;
- Print_COM_Board;
- If Mode='EASY'then
- COM_Random_Pick
- else
- If Mode='NORMAL'then
- COM_Smart_Pick
- else COM_God_Pick;
- If (HumanVictoryCondition) and (COMVictoryCondition) then Tie
- else
- Begin
- If (HumanVictoryCondition) then HumanWon_COMLost;
- If (COMVictoryCondition) then COMWon_HumanLost;
- End;
- End;
- End;
- Begin
- clrscr;
- Init_Board;
- Init_COM_Board;
- Print_Human_Board;
- Writeln;
- Print_COM_Board;
- Play;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement