1 #include <aros/oldprograms.h>
2 #include "exec/types.h"
3 #include "intuition/intuition.h"
8 struct IntuitionBase
*IntuitionBase
;
9 struct GfxBase
*GfxBase
;
10 struct RastPort
*r
,*r2
;
11 struct Window
*Wind
,*abWind
;
12 struct NewWindow NewWindow
,NewWindow2
;
13 struct IntuiMessage
*mesg
;
14 struct IntuiText prompt
,yprompt
,t0
,t1
;
16 struct MenuItem m0
,m1
;
17 struct TextFont
*topazfont
;
19 #define INTUITION_REV 29
20 #define GRAPHICS_REV 29
29 BOOL gamewon
=FALSE
,firstmove
=TRUE
;
30 USHORT mclass
,mcode
,msx
,msy
;
31 SHORT d
,i
,j
,k
,l
,x
,y
,amx
,amy
,start
;
32 SHORT lx
,ly
,pla
,opp
,x0
,x1
,y0
,y1
,max
,value
;
34 SHORT Board
[n
+1][n
+1],Aline
[4][n
+1][n
+1][2],Value
[n
+1][n
+1][2];
37 static SHORT Weight
[]={0,0,4,20,100,500,0};
40 void OpenALL(),Human(),AddUp(),UpdateValue(),MakeMove(),FindMove();
41 void CreateMes(),DrawFrame(),make_window(),init_newgame();
42 void setup_menu(),show_About();
44 struct TextAttr topaz8
=
49 int main(int argc
, char **argv
)
59 SetMenuStrip(Wind
,&Menu1
);
63 CreateMes(&yprompt
,3,3," OK ");
68 if(start
== 0) goto Human_first
;
86 Move(r
,x0
+14,y0
+wintop
+5);
87 Draw(r
,x0
+26,y0
+wintop
+13);
88 Move(r
,x0
+14,y0
+wintop
+13);
89 Draw(r
,x0
+26,y0
+wintop
+5);
99 CreateMes(&prompt
,50,5,"I won");
100 AutoRequest(Wind
,&prompt
,&yprompt
,&yprompt
,0,0,160,50);
114 CreateMes(&prompt
,37,5,"You won!");
115 AutoRequest(Wind
,&prompt
,&yprompt
,&yprompt
,0,0,160,50);
127 /* Set Up an IDCMP Read Loop */
129 Wait (1 << Wind
->UserPort
->mp_SigBit
);
131 while((mesg
=(struct IntuiMessage
*) GetMsg(Wind
->UserPort
)) != NULL
) {
136 ReplyMsg((struct Message
*)mesg
);
141 if(ITEMNUM(mcode
) == 0) {
142 ClearMenuStrip(Wind
);
145 while(((mesg
=(struct IntuiMessage
*) GetMsg(Wind
->UserPort
)) != NULL
)) ReplyMsg((struct Message
*)mesg
);
147 SetMenuStrip(Wind
,&Menu1
);
150 else if(ITEMNUM(mcode
) == 1) { /* Quit */
151 ClearMenuStrip(Wind
);
159 if(ReadPixel(r
,msx
,msy
) == 2) goto HumanLoop
; /* black line */
160 if(msx
< 10 || msx
> 10+n
*20) goto HumanLoop
; /* outside board */
161 if(msy
< wintop
+1 || msy
> wintop
+1+n
*CELLHEIGHT
) goto HumanLoop
; /* outside board */
163 y
=((msy
-wintop
-1)/CELLHEIGHT
)+1;
165 if(Board
[x
][y
] > 0) goto HumanLoop
; /* occupied square */
169 j
=(y
-1)*CELLHEIGHT
+wintop
+5;
194 if(x1
>=1 && x1
<=n
-4) {
205 if((x1
>=1 && x1
<=n
-4) && (y1
>=1 && y1
<=n
-4)) {
216 if((x1
>=5 && x1
<= n
) && (y1
>=1 && y1
<=n
-4)) {
227 if(y1
>=1 && y1
<=n
-4) {
239 Aline
[d
][x1
][y1
][pla
] = Aline
[d
][x1
][y1
][pla
] + 1;
241 if(Aline
[d
][x1
][y1
][pla
] == 5) gamewon
=TRUE
;
265 if(Aline
[d
][x1
][y1
][opp
] == 0) Value
[x1
+lx
][y1
+ly
][pla
] = Value
[x1
+lx
][y1
+ly
][pla
] + Weight
[Aline
[d
][x1
][y1
][pla
]+1] - Weight
[Aline
[d
][x1
][y1
][pla
]];
266 else if(Aline
[d
][x1
][y1
][pla
] == 1) Value
[x1
+lx
][y1
+ly
][opp
] = Value
[x1
+lx
][y1
+ly
][opp
] - Weight
[Aline
[d
][x1
][y1
][opp
]+1];
276 if(Board
[x
][y
] == 0) max
=4;
280 if(Board
[i
][j
] == 0) {
281 value
=Value
[i
][j
][pla
] * (16 + AttackFactor
) / 16 + Value
[i
][j
][opp
];
293 VOID
OpenALL() /* Open required libraries */
296 IntuitionBase
=(struct IntuitionBase
*) OpenLibrary("intuition.library",INTUITION_REV
);
298 if(IntuitionBase
== NULL
) exit(FALSE
);
300 GfxBase
=(struct GfxBase
*) OpenLibrary("graphics.library",GRAPHICS_REV
);
302 if(GfxBase
== NULL
) exit(FALSE
);
306 VOID
CreateMes(x
,left
,top
,mes
)
328 Draw(r
,amx
+14,amy
+10);
334 VOID
make_window() /* Open a plain window */
339 scr
= LockPubScreen(NULL
);
342 wintop
= scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1;
343 UnlockPubScreen(NULL
, scr
);
346 NewWindow
.LeftEdge
=0;
349 NewWindow
.Height
=311 + wintop
; //159 + wintop;
350 NewWindow
.DetailPen
=-1;
351 NewWindow
.BlockPen
=-1;
352 NewWindow
.Title
="Five In Line";
353 NewWindow
.Flags
=ACTIVATE
|WINDOWDRAG
|WINDOWDEPTH
|SMART_REFRESH
;
354 NewWindow
.IDCMPFlags
=MOUSEBUTTONS
|MENUPICK
;
355 NewWindow
.Type
=WBENCHSCREEN
;
356 NewWindow
.FirstGadget
=NULL
;
357 NewWindow
.CheckMark
=NULL
;
358 NewWindow
.Screen
=NULL
;
359 NewWindow
.BitMap
=NULL
;
360 NewWindow
.MinWidth
=0;
361 NewWindow
.MinHeight
=0;
362 NewWindow
.MaxWidth
=640;
363 NewWindow
.MaxHeight
=200;
365 topazfont
= OpenFont(&topaz8
);
367 Wind
=(struct Window
*) OpenWindow(&NewWindow
);
368 if (topazfont
) SetFont(Wind
->RPort
, topazfont
);
375 start
=1-start
; /* toggle between computer and human */
385 for(pla
=0;pla
<=1;pla
++)
386 Aline
[d
][x
][y
][pla
]=0;
393 for(pla
=0;pla
<=1;pla
++)
399 RectFill(r
,10,wintop
+1,400,Wind
->Height
-Wind
->BorderBottom
- 1); /* blank board */
407 for(x
=10;x
<=10+n
*20;x
=x
+20) {
409 Draw(r
,x
,wintop
+1+n
*CELLHEIGHT
);
412 for(y
=wintop
+1;y
<=wintop
+1+n
*CELLHEIGHT
;y
=y
+CELLHEIGHT
) {
420 Move(r
,420,19+wintop
);
422 Move(r
,450,19+wintop
);
423 len
=sprintf(text
,"%3d",xv
);
426 Move(r
,420,34+wintop
);
428 Move(r
,450,34+wintop
);
429 len
=sprintf(text
,"%3d",ov
);
437 CreateMes(&t0
,0,0,"About");
444 m0
.Flags
=ITEMTEXT
|HIGHCOMP
|ITEMENABLED
;
446 m0
.ItemFill
=(APTR
)&t0
;
451 CreateMes(&t1
,0,0,"Quit");
458 m1
.Flags
=ITEMTEXT
|HIGHCOMP
|ITEMENABLED
;
460 m1
.ItemFill
=(APTR
)&t1
;
470 Menu1
.Flags
=MENUENABLED
;
471 Menu1
.MenuName
="Project";
480 NewWindow2
.LeftEdge
=Wind
->LeftEdge
+ 40;
481 NewWindow2
.TopEdge
=Wind
->TopEdge
+ 45;
482 NewWindow2
.Width
=400;
483 NewWindow2
.Height
=69+wintop
;
484 NewWindow2
.DetailPen
=-1;
485 NewWindow2
.BlockPen
=-1;
486 NewWindow2
.Title
="About Five In Line";
487 NewWindow2
.Flags
=ACTIVATE
|WINDOWCLOSE
|SMART_REFRESH
;
488 NewWindow2
.IDCMPFlags
=CLOSEWINDOW
;
489 NewWindow2
.Type
=WBENCHSCREEN
;
490 NewWindow2
.FirstGadget
=NULL
;
491 NewWindow2
.CheckMark
=NULL
;
492 NewWindow2
.Screen
=NULL
;
493 NewWindow2
.BitMap
=NULL
;
494 NewWindow2
.MinWidth
=0;
495 NewWindow2
.MinHeight
=0;
496 NewWindow2
.MaxWidth
=640;
497 NewWindow2
.MaxHeight
=200;
499 abWind
=(struct Window
*) OpenWindow(&NewWindow2
);
501 if (topazfont
) SetFont(r2
, topazfont
);
504 Move(r2
,10,wintop
+9);
505 Text(r2
,"Placed in Public Domain 1988",28);
506 Move(r2
,10,wintop
+19);
507 Text(r2
,"by Njål Fisketjøn.",18);
509 Move(r2
,10,wintop
+39);
510 Text(r2
,"Algorithm from a",16);
513 Move(r2
,146,wintop
+39);
514 Text(r2
,"Borland Turbo Pascal",20);
517 Move(r2
,314,wintop
+39);
518 Text(r2
,"program.",8);
520 Move(r2
,10,wintop
+59);
521 Text(r2
,"Close window to continue playing.",33);
523 Wait (1 << abWind
->UserPort
->mp_SigBit
);
524 while((mesg
=(struct IntuiMessage
*) GetMsg(abWind
->UserPort
)) != NULL
) ReplyMsg((struct Message
*)mesg
);