The Daily Click ::. Forums ::. Klik Coding Help ::. I'm making a connect 4 game, but...
 

Post Reply  Post Oekaki 
 

Posted By Message

Gongashplei



Registered
  02/01/2002
Points
  164
21st August, 2003 at 07:00:35 -

Well i've starting making a connect 4 engine and so far its working fine and dandy except for one slightly vital factor. so far the game doesnt detect if pieces are lined up in a line of four and ive tried a few methods unsuccessfully. i know i'd need sensor objects but where to put them and how theyd work totally baffle me. any one got ideas?

 
Gongashplei- Now celebrating a year of membership with no DC points!

AsparagusTrevor

Mine's a pint of the black stuff

Registered
  20/08/2002
Points
  2364

Game of the Week WinnerHas Donated, Thank You!VIP MemberEvil kliker
21st August, 2003 at 07:08:27 -

Couldn't you have a 8 detector objects shoot out from the piece that's just been dropped. Then when a detector object hits a piece of the same colour, that piece also shoots a detector and 1 is added to a counter, then if the new detector hits another same coloured piece, that shoots another detector and another is added to a counter, until the counter reaches 3 (cos the first piece wouldn't need to add 1 to the counter) then the score can be given.

Dunno if I wrote that in a way nobody could understand, but I think it would work.

 
Image

Pete Nattress

Cheesy Bits img src/uploads/sccheesegif

Registered
  23/09/2002
Points
  4811
21st August, 2003 at 07:10:28 -

you could use an array, have stuff like;

+ value at focus = 1
+ value at "x of focus-1","y of focus-1" = 1
- do event

that would check if there was a piece up and to the left, for instance.

 
www.thenatflap.co.uk

Gongashplei



Registered
  02/01/2002
Points
  164
21st August, 2003 at 07:25:07 -

yeh asp trev ive considered that method, but the problem is when theres more of the same colour in a potiential row nearby. eg the counter detects a piece above the new piece and two beside it and connects four even though they arent in a line. obviously this problem could be ficed with more seperate counters but i was hoping for a simpler solution. thanks anyhow, thats the method i'll be using for the time being.

 
Gongashplei- Now celebrating a year of membership with no DC points!

alibaba



Registered
  07/05/2003
Points
  296
21st August, 2003 at 07:39:24 -

I think asapragus dude method will work but slightly adapeted- at the start (or end) of each turn, pick a red counter (say) at random. Have this shoot a object first in the direction right. If it colides with anohter red counter make it add 1 to a value but dont destroy it. if it hits a yellow counter, make it destory the shooting object and set the counter to one again. This way, the shot object will move along hitting all the red counters in a row unitl it is destoryed - there fore if it hits 4 u know there are four in a row.

Then shoot the object in a diagonal direction, and see if u can get the value up to four. if not, try anohter direction., until all 8 have been tryed.

P.s - u will have to repeat this on every red piece since this method will only count to four (or 3 excluding the selected counter) on the pieces which are at the end of a row. - this is time consuming but is the easiest way of achieveing this effect.(?maybe?)

 
I love gold

Gongashplei



Registered
  02/01/2002
Points
  164
21st August, 2003 at 21:07:05 -

thanks for the help guys, i've got it working now, i needed 7 (not 8 ) detectors and 4 sperate direction detector counters. so yeh thanks again thats the 2 player mode sorted, im gonna have a stab at making some AI as well, if i get stuck you'll be hearing from me... thanks

 
Gongashplei- Now celebrating a year of membership with no DC points!

alibaba



Registered
  07/05/2003
Points
  296
22nd August, 2003 at 09:40:07 -

Glad u got it working - i had to dothis in java for a project and let me tell u it was a lot harder in that hehe - look forward to playing i could prob send u the AI i used for my 1 player version , but it was done using arrays so the same theories do not directly apply- still might be usefull?

 
I love gold
   

Post Reply



 



Advertisement

Worth A Click