Older Contests
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP ContestsOlder Contests

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old June 13th, 2003, 07:50 PM
lphuberdeau lphuberdeau is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: St-Eustache, Quebec, Canada
Posts: 107 lphuberdeau User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to lphuberdeau
[Trilite] Question about play

This might seem like a basic question but I don't quite understand the process. When both players reach 3 markers, when they add an other one, the first they added is removed. What I am wondering is if the first marker is removed before or after the move. Can a line be made while there are 4 tiles (before it is removed) or there are just never 4 tiles? In other words, is the process:

Add marker
Remove marker
Check for line

or

Add maker
check for line
Remove marker

The contest seem quite interesting, I never participated but it will be quite fun.

Reply With Quote
  #2  
Old June 14th, 2003, 12:05 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: [Trilite] Question about play

This contest is actually over. I have just been slacking on updating the page. I will do so later tonight...

A new contest will be here soon!

Reply With Quote
  #3  
Old June 14th, 2003, 09:37 PM
cagrET cagrET is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Poland
Posts: 19 cagrET User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: [Trilite] Question about play

Matt why didnt u announce results ? (news, mail etc)

btw what was the 4th 5th and 6th place ?

Reply With Quote
  #4  
Old June 15th, 2003, 01:05 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: [Trilite] Question about play

Sorry....I have been slacking big time...it is done now....

except for 4,5,6 places...it is not happening...

Reply With Quote
  #5  
Old June 15th, 2003, 11:23 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: [Trilite] Question about play

why u didnt post a news ?

Reply With Quote
  #6  
Old June 16th, 2003, 10:41 PM
lphuberdeau lphuberdeau is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: St-Eustache, Quebec, Canada
Posts: 107 lphuberdeau User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to lphuberdeau
RE: [Trilite] Question about play

Quite sad, I had spent at least 3 hours on it. Seem like I won't ever know how it performed.

Reply With Quote
  #7  
Old June 17th, 2003, 07:31 AM
xs0 xs0 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Ljubljana, Slovenia
Posts: 760 xs0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: [Trilite] Question about play

Well, you can run it against other scripts yourself... It's all on FTP

Reply With Quote
  #8  
Old June 17th, 2003, 09:30 PM
lphuberdeau lphuberdeau is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: St-Eustache, Quebec, Canada
Posts: 107 lphuberdeau User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to lphuberdeau
RE: [Trilite] Question about play

After looking at the winning scripts, I noticed the extremely low ammount of comments in the code. Do you guys think it affects performences or something? In two years from now, will the winner be able to explain his own code? As I said before, I never participated and have nothing to do with the management of the contest, but I think participants should take some time making their code readable before submitting.

Here is what I wrote (pretty much an example of abusive comments but anyway). I never actually executed the script, it probably contains a few parse errors, don't bother.

If you guys want to pretend you are pro coders, you should code as if you were. I don't know any enterprise that accept non-readable code due to the fact that it almost can't be maintained.

Also, these contests have an educational value, so code should be used as examples for others to learn on without the need of decrypting.

Ok, I stop rambling now.

php Code:
Original - php Code
  1.  
  2. <?php
  3. /*
  4.    By:
  5.    Louis-Philippe Huberdeau
  6.    lphuberdeau@sympatico.ca
  7. */
  8.  
  9. define( 'FILE_CURRENT_GAME', 'current.txt' );
  10. define( 'X', '1' );
  11. define( 'O', '2' );
  12.  
  13. // Board class
  14. // Contains and store board states
  15. class Board
  16. {
  17.     var $board;
  18.     var $list;
  19.     var $start;
  20.    
  21.     // Constructor
  22.     function Board( $new = false )
  23.     {
  24.         $this->board = array( false, false, false,
  25.                               false, false, false,
  26.                               false, false, false );
  27.  
  28.         if( $new )
  29.         {
  30.             // New game requested, clear the data file
  31.             $this->list = array( X => array(), O => array() );
  32.         }
  33.         else
  34.         {
  35.             $file = file( FILE_CURRENT_GAME );
  36.  
  37.             // If the file does not contain the right data, exit
  38.             if( sizeof( $file ) != 3 ) die( "Invalid data file." );
  39.            
  40.             // Get the player who started on the first line
  41.             $this->start = $file[0];
  42.  
  43.             // Read two lines
  44.             for( $i = 0; 2 > $i; $i++ )
  45.             {
  46.                 // Get the right elements in the file: X|O = [0-8]{0,3}
  47.                 if( preg_match( "/(" . X . "|" . O . ")s*=s*([0-8]{0,3})/i", $file[$i], $parts ) )
  48.                 {
  49.                     // Kill the script if both rows are the same
  50.                     if( is_array( $parts[1] ) ) die( "User data already exists." );
  51.  
  52.                     $this->list[ $parts[1] ] = array();
  53.  
  54.                     // For each marker in the file
  55.                     for( $j = 0; strlen( $parts[2] ) > $j; $j++ )
  56.                     {
  57.                         // Add the marker, if not valid, break execution
  58.                         if( !$this->addMarker( $parts[1], $parts[2][$j] ) ) die( "Tile already in use." );
  59.                     }
  60.                 }
  61.                 else
  62.                 {
  63.                     // Pattern not found, error in file
  64.                     die( "Bad pattern for user data." );
  65.                 }
  66.             } // end for
  67.         } // end new if
  68.     } // end constructor
  69.  
  70.     // Methods
  71.     function addMarker( $player, $position )
  72.     {
  73.         // Validate the tile
  74.         if( $position < 0 || $position > 8 ) return false;
  75.  
  76.         // Make sure it is currently empty
  77.         if( $this->board[ $position ] != 0 ) return false;
  78.  
  79.         // Set it as the player's
  80.         $this->board[ $position ] = $player;
  81.        
  82.         // Add an element to the end of the list and if too many remain
  83.         if( array_push( $this->list[ $player ], $position ) > 3 )
  84.         {
  85.             // Remove the first
  86.             $old = array_shift( $this->list[ $player ] );
  87.             $this->board[ $old ] = false;
  88.         }
  89.        
  90.         return true;
  91.     }
  92.  
  93.     function containsLine( $player )
  94.     {
  95.         $patterns = getPatterns();
  96.  
  97.         // Scan all patterns and see if there is a match
  98.         foreach( $patterns as $pattern )
  99.         {
  100.             // Check every tile until wrong one is found or end is reached
  101.             for( $i = 0; 3 > $i && $this->board[ $pattern[$i] ] == $player; $i++ );
  102.  
  103.             // End was reached, there is a line
  104.             if( $i == 3 ) return true;
  105.         }
  106.  
  107.         // No lines were found
  108.         return false;
  109.     }
  110.  
  111.     function getLastMove( $player )
  112.     {
  113.         if( !is_array( $this->list[ $player ] ) ) return false;
  114.         if( ( $position = sizeof( $this->list[ $player ] ) - 1 ) >= 0 ) return false;
  115.        
  116.         return $this->list[ $player ][ $position ];
  117.     }
  118.  
  119.     function getPatterns()
  120.     {</