English Amiga Board

English Amiga Board (http://eab.abime.net/index.php)
-   Coders. C/C++ (http://eab.abime.net/forumdisplay.php?f=118)
-   -   Four In A Row code - "Complete Amiga C" (http://eab.abime.net/showthread.php?t=102366)

Toki 23 May 2020 12:38

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*.

thomas 23 May 2020 12:47

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);
}


Toki 23 May 2020 13:01

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();
                }


a/b 23 May 2020 13:35

Code:

//                message+(struct IntuiMessage *)GetMsg(CurrentWindow->UserPort);
                message=(struct IntuiMessage *)GetMsg(CurrentWindow->UserPort);


Toki 23 May 2020 14:21

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".

a/b 23 May 2020 15:14

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).

Toki 23 May 2020 15:46

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();
                }



All times are GMT +2. The time now is 15:53.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.

Page generated in 0.04202 seconds with 11 queries