Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-19-2009, 08:24 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
data structures

boredom struck and I couldn't really find anything involving queues and stacks on the wiki (ActionMap has a push and pop which confused me) so I wrote up a queue real quick.

the most practical use I can think of for this right now is a spar system, where players joining the line are pushed on the queue, and you use a pop to get who's next in line.

I'll add a stack and some other data structures potentially tomorrow when I'm not tired.

queue:
PHP Code:
public function onCreated()
{
  
this.data = {null};
}

public function empty()
{
  if (
front() == null)
    return 
true;
  return 
false;
}

public function 
front()
{
  if(
this.data[0] == null)
    return 
null;
  else
    return 
this.data[0];
}

public function 
enqueueobj)
{
  
this.data.addobj);
}

public function 
dequeue()
{
  
this.data.remove(this.data[0]);
}

public function 
pushobj)
{
  
enqueue(obj);
}

public function 
pop()
{
  
temp.ret front();
  
dequeue();
  return 
ret;

Reply With Quote
  #2  
Old 03-19-2009, 08:40 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
That's a fairly good exercise. I remember taking a data structures course a few years ago, and we had to implement these things from scratch (sort of similar to what you did). Any chance this is inspired by such a course?

Just some things I noticed:
You could simplify the empty() function:
PHP Code:
public function empty() { 
  return 
front() == null;

And, the front() function just needs to be:
PHP Code:
public function front() { 
    return 
this.data[0]; 

I have a feeling you may have ported that bit over from Java or something from the way you're dealing with the null case.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #3  
Old 03-19-2009, 08:42 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
Quote:
Originally Posted by napo_p2p View Post
That's a fairly good exercise. I remember taking a data structures course a few years ago, and we had to implement these things from scratch (sort of similar to what you did). Any chance this is inspired by such a course?

Just some things I noticed:
You could simplify the empty() function:
PHP Code:
public function empty() { 
  return 
front() == null;

And, the front() function just needs to be:
PHP Code:
public function front() { 
    return 
this.data[0]; 

I have a feeling you may have ported that bit over from Java or something from the way you're dealing with the null case.

I've written mostly in java, haven't done data structures since sophomore year in high school when I took AP CS AB.

Was working on something earlier today, thought a queue would be useful, couldn't find a graal version anywhere.
Reply With Quote
  #4  
Old 03-19-2009, 04:12 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Reminds me of associative arrays ;o

http://forums.graalonline.com/forums...ad.php?t=68643
__________________
Reply With Quote
  #5  
Old 03-19-2009, 05:28 PM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by Mark Sir Link View Post
I've written mostly in java, haven't done data structures since sophomore year in high school when I took AP CS AB.
Ahh, same class .
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #6  
Old 03-20-2009, 05:05 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Stefan should simply add pushback(), pushfront(), popback(), and popfront() functions to the TGraalVar which would allow the array to be used as a queue or stack.
__________________
Reply With Quote
Reply


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 10:36 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.