[Kde-games-devel] Re: Kplayer and game logic

cantabile cantabile.03 at wanadoo.fr
Sun Aug 31 23:58:16 CEST 2003


Hi again,
I'm on my way to create a computer player. The inherited class is called
ComputerPlayer (I'm quite creative for class names :) ) and constructs
like this:

ComputerPlayer():KGameIO(){};

When I try and create this player in an initPlayers() method, calling a
createIO method I get a program crash with this code :

[New Thread 1092861856 (LWP 16541)]
0xffffe002 in ?? ()
#0  0xffffe002 in ?? ()
#1  0x4068f57d in KCrash::defaultCrashHandler(int) ()
   from /usr/lib/libkdecore.so.4
#2  <signal handler called>
#3  0x4073187c in KCompTreeNode::alloc () from /usr/lib/libkdecore.so.4
#4  0x40c776a4 in QGList::append(void*) ()
   from /usr/lib/qt-3.1/lib/libqt-mt.so.3
#5  0x40076c25 in KPlayer::addGameIO(KGameIO*) ()
   from /usr/lib/libkdegames.so.1
#6  0x08053671 in KMatchesDoc::createIO(KPlayer*, KGameIO::IOMode) (
    this=0x811e688, player=0x813af68, io=ComputerIO)
    at /home/davidoff/projets/Kdev3/matches/src/kmatchesdoc.cpp:107
#7  0x080535d7 in KMatchesDoc::createPlayer(int, int, bool)
(this=0x811e688, 
    rtti=2, io=16, isvirtual=false)
    at /home/davidoff/projets/Kdev3/matches/src/kmatchesdoc.cpp:78
#8  0x080534ca in KMatchesDoc::initPlayers() (this=0x811e688)
    at /home/davidoff/projets/Kdev3/matches/src/kmatchesdoc.cpp:53
#9  0x080533f2 in KMatchesDoc::initGame() (this=0x811e688)
    at /home/davidoff/projets/Kdev3/matches/src/kmatchesdoc.cpp:37
#10 0x08053412 in KMatchesDoc::init(KMatchesView*) (this=0x811e688, 
    view=0x8121220)
    at /home/davidoff/projets/Kdev3/matches/src/kmatchesdoc.cpp:42
#11 0x08051ae3 in Matches (this=0x810dad0)
    at /home/davidoff/projets/Kdev3/matches/src/matches.cpp:22
#12 0x080517ab in main (argc=1, argv=0xbfffe474)
    at /home/davidoff/projets/Kdev3/matches/src/main.cpp:43
#13 0x420156a4 in __libc_start_main () from /lib/tls/libc.so.6

Here are the lines where I create a computer player
switch(io) {
        case (KGameIO::MouseIO):
                KGameMouseIO *mouse_input;
                mouse_input=new KGameMouseIO(boardView);
                // Connect mouse input to a function to process the
actual input
                //     connect(input,SIGNAL(signalMouseEvent(KGameIO
*,QDataStream &,QMouseEvent *,bool *)),
                //             boardView,SLOT(slotMouseInput(KGameIO
*,QDataStream &,QMouseEvent *,bool *)));
                player->addGameIO(mouse_input);
                break;
        case (KGameIO::ComputerIO):
		KGameComputerIO *computer_input;
		computer_input=new KGameComputerIO();
                // Connect mouse input to a function to process the
actual input
                //     connect(input,SIGNAL(signalMouseEvent(KGameIO
*,QDataStream &,QMouseEvent *,bool *)),
                //             boardView,SLOT(slotMouseInput(KGameIO
*,QDataStream &,QMouseEvent *,bool *)));		
                player->addGameIO(computer_input);
		break;
        // other KGameIO modes won't be used
	default:
                break
}

I noticed, though, that I must cast(1) computer to KPlayer* because
addPlayer(KGameIO*) isn't available. Would it be the soure of my problem
here ? Is there another way to add this specific player?


Thanks.
-------------------------------------------
(1) e.g : addPlayer((KPlayer* )computer); seems correct to me...


> You are using KGame/KPlayer?
> Then you should do your computer player in a KGameIO derived class, _not_ in 
> KPlayer. Then you can easily switch between network and computer player, 
> which is the reason behind it all.
> Furthermore it is easier :)




More information about the kde-games-devel mailing list