English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 23 May 2020, 12:38   #1
Toki
Registered User

Toki's Avatar
 
Join Date: Feb 2016
Location: Birmingham
Age: 56
Posts: 51
Four In A Row code - "Complete Amiga C"

Just wondered if anyone has successfully got the the Four in a Row code to work in Cliff Ramshaw's Amiga Shopper Complete Amiga C book?

I've got the other codes in the book to compile using Lattice C, but this one is eluding me.

I've just got one "warning" left when to resolve concerning the reply(message) at the end of the code. The compiler says it expects struct message* and found struct IntuiMessage*.
Toki is offline  
Old 23 May 2020, 12:47   #2
thomas
Registered User
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 5,999
I don't know this book and you didn't post any code, but I can tell you the typical message loop for a window looks like this:

Code:
struct IntuiMessage *imsg;

while ((imsg = (struct IntuiMessage *) GetMsg (window->UserPort)))
{
	switch (imsg->Class)
	{
	case IDCMP_CLOSEWINDOW:
		finish = TRUE;
		break;
	}

	ReplyMsg ((struct Message *) imsg);
}
thomas is offline  
Old 23 May 2020, 13:01   #3
Toki
Registered User

Toki's Avatar
 
Join Date: Feb 2016
Location: Birmingham
Age: 56
Posts: 51
Thanks for the suggestion.

The code finishes with the following (it's the two "ReplyMsg(message)" functions which the compiler has the warning about). The program still compiles, and the window opens fine but the games doesn't play. Here's how the code finishes with the two ReplyMsg(message) functions. I could copy and paste the entire code, but it might be too large to post:

Code:
        do {
            do{
                /* put up message telling player it's their turn */
                
                SetAPen(rp,4);  /* pen colour */
                Move(rp,283,18);
                Text(rp,"Your Move",9);
                
                Wait(1L<< CurrentWindow->UserPort->mp_SigBit);  /* wait until we receive message */
                /* find out the kind of message received */
                message+(struct IntuiMessage *)GetMsg(CurrentWindow->UserPort);
                
                class=message->Class;
                Humansmove=getmove(class,message);
                ReplyMsg(message);
                if (class!=CLOSEWINDOW) {
                    /* if user hasnit closed the window , then wait for and get next message */
                    /*  This absorbs the mouse button release message
                    Intuition fives after the user clicks the mouse */
                    Wait(1L<< CurrentWindow->UserPort->mp_SigBit);  /* wait
                    for message */
                        message = (struct IntuiMessage *)GetMsg(
                    CurrentWindow->UserPort);
                    
                    ReplyMsg(message);
                    }
                } while (class!=CLOSEWINDOW && HumansMove<0);  /* repeat until user 
                selects close or enters a valis move */
                if (class ==CLOSEWINDOW)
                TimeToQuit=true;
            else {
                drawpieces(Human,HumansMove,NextFree[HumansMove]);
                AlterBoard(TheBoard,Human,Humansmove);
                
                /* let player know computer is thinking */
                SetAPen(rp,4); /* set pen colur */
                Move(rp,283,18);
                Text(rp,"My move  ",9);
                
    ComputersMove = BestMove(TheBoard,Computer,LookAhead,&ComputersScore);
                drawpiece(Computer,ComputersMove,NextFree[ComputersMove]);
                AlterBoard(TheBoard,Computer,ComputersMove);
                }
             } while (TimeToQuit==false);  /* repeat until user asks to
             close the window */
             }
             
             void main(void)
             {
                PlayGame();
                ReleaseResources();
                }
Toki is offline  
Old 23 May 2020, 13:35   #4
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 180
Code:
//                message+(struct IntuiMessage *)GetMsg(CurrentWindow->UserPort);
                message=(struct IntuiMessage *)GetMsg(CurrentWindow->UserPort);
a/b is offline  
Old 23 May 2020, 14:21   #5
Toki
Registered User

Toki's Avatar
 
Join Date: Feb 2016
Location: Birmingham
Age: 56
Posts: 51
Thanks. I swapped "message=" with "message+" as you've suggested. This time it's saying "operation cannot be performed on a pointer".

and it's still got the original warning about expecting "struct Message *" found "struct IntuiMessage".
Toki is offline  
Old 23 May 2020, 15:14   #6
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 180
Not sure if that's a typo in your actual code or only the snippet you posted, but this line you posted is wrong:
Code:
                message+(struct IntuiMessage *)GetMsg(CurrentWindow->UserPort);
and should read:
Code:
                message=(struct IntuiMessage *)GetMsg(CurrentWindow->UserPort);
So it should be equivalent to the second GetMsg() call about 10 lines below. And the "operation cannot be performed..." error shouldn't occur.

> and it's still got the original warning about expecting "struct Message *" found "struct IntuiMessage".
Found "struct IntuiMessage" or found "struct IntuiMessage *"? That's a big difference. How is message declared? I pressume it's a pointer (struct IntuiMessage*), otherwise the compiler would complain about a lot of other stuff.
Replace all
Code:
                    ReplyMsg(message);
with
Code:
                    ReplyMsg((struct Message *)message);
ReplyMsg is a generic function, it accepts all kinds of messages, so you have to cast the argument to a pointer to generic Message in order to quiet the compiler (IntuiMessage is just an extended generic Message, with some extra stuff at the end).
a/b is offline  
Old 23 May 2020, 15:46   #7
Toki
Registered User

Toki's Avatar
 
Join Date: Feb 2016
Location: Birmingham
Age: 56
Posts: 51
Thanks, this has helped, thanks very much.

The program compiles now with no errors.

However on loading the program it still doesn't run properly. It loads a the window with the board, click on the board and a circle appears on the grid , but nothing else.

Here is the code at the end of the full code, now with your suggestions.

I'm now not sure if the code in this book ever worked.

Code:
do {
            do{
                /* put up message telling player it's their turn */
                
                SetAPen(rp,4);  /* pen colour */
                Move(rp,283,18);
                Text(rp,"Your Move",9);
                
                Wait(1L<< CurrentWindow->UserPort->mp_SigBit);  /* wait */
                /* until we receive message */
                /* find out the kind of message received */
                message=(struct IntuiMessage *)GetMsg(CurrentWindow->UserPort);
                
                class=message->Class;
                HumansMove=GetMove(class, message);
                ReplyMsg((struct Message *)message);
                if (class!=CLOSEWINDOW) {
                    /* if user hasn't closed the window, then wait forR
                    and get next message */
                    /*  This  absorbs the mouse button release message
                    Intuition fives after the user clicks the mouse */
                    Wait(1L<< CurrentWindow->UserPort->mp_SigBit);  /* wait
                    for message */
                 message=(struct IntuiMessage *)GetMsg(CurrentWindow->UserPort);
                    
                    ReplyMsg((struct Message *)message);
                    }
                } while (class!=CLOSEWINDOW && HumansMove<0);  /* repeat until user 
                selects close or enters a valis move */
                if (class ==CLOSEWINDOW)
                TimeToQuit=true;
            else {
                drawpiece(Human,HumansMove,NextFree[HumansMove]);
                AlterBoard(TheBoard,Human,HumansMove);
                
                /* let player know computer is thinking */
                SetAPen(rp,4); /* set pen colur */
                Move(rp,283,18);
                Text(rp,"My move  ",9);
                
    ComputersMove = BestMove(TheBoard,Computer,LookAhead,&ComputersScore);
                drawpiece(Computer,ComputersMove,NextFree[ComputersMove]);
                AlterBoard(TheBoard,Computer,ComputersMove);
                }
             } while (TimeToQuit==false);  /* repeat until user asks to
             close the window */
             }
             
             void main(void)
             {
                PlayGame();
                ReleaseResources();
                }
Toki is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Skid Row Crackintro "Lemmings" way too slow 1988 support.WinUAE 5 08 May 2015 17:58
Companion Disks "Complete Amiga C" from Cliff Ramshaw Dwyloc request.Apps 9 11 May 2014 02:25
Companion Disks "Complete Amiga C" by Cliff Ramshaw D4Ni3L3 request.Apps 14 24 April 2013 01:43
Companion Disks "Complete Amiga C" from Cliff Ramshaw Herpes Coders. General 5 28 March 2010 14:03
Unknown "Skid Row" module Old Fool request.Modules 3 11 September 2009 14:22

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:57.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.06879 seconds with 15 queries