Contest Code
  Home arrow Contest Code arrow CTF-Judge, better "auto" controls
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CONTEST CODE

CTF-Judge, better "auto" controls
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-08-13

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    This is from Zombie's, copy and replace this over Zombie's judge.php
    You can set the time-out from the GUI.
    VERY important, that I found out the hard way:
    since your script is being included (and not executed as the real contest will be done), do NOT use global in your functions, as that looks for global variables in judge.php's global scope and NOT your capture.php's global scope.

    By : webhappy

    <?php

    /* *\

    project: Capture The Flag: php competition on codewalkers.com

    file: judge.php: script that plays a match between robots

    author: zombie: Tomica Jovanovic <tomica00@mail.com>

    disclaimer: this script is distributed in the hope that it will
    be useful, but it is provided "AS IS" and WITHOUT
    ANY WARRANTY, without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    See the GNU General Public License for more details.

    more info: see the README file for more info...

    \* */



    // this function is colled only on first turn of the mach... if it doesn't find white
    // and red robot script dirs, it goes back to the start page, WITHOUT any msg... sorry ;)

    function start($white, $red) {
    if (!file_exists($white) or !file_exists($red)) die(header('Location: start.php'));
    $w=array('n'=>$white, 'x'=>0, 'y'=>1, 'i'=>'STARTWHITE', 's'=>array(), 'd'=>0, 't'=>-1, 'l'=>0);
    $r=array('n'=>$red, 'x'=>29, 'y'=>27, 'i'=>'STARTRED', 's'=>array(), 'd'=>0, 't'=>-1, 'l'=>0);
    @unlink("$w[n]/data.txt");
    @unlink("$r[n]/data.txt");
    return array('w'=>$w, 'r'=>$r, 'c'=>'w', 'b'=>array(93=>'lime', 806=>'lime'));
    }



    // this function is colled to execute the robot scripts. include is placed in the separate
    // function so that robot scripts don't mess up our variables. if u want to run the scripts
    // from the command line (like the rules say) change include() line into smth like example
    // NOTE: u must NOT use die() in ur robot scripts if u don't change include() to exec()

    function run() {
    include('capture.php');
    // exec("/path/to/php capture.php");
    }



    // checks if position ($x, $y) is on the grid

    function valid($x, $y) {
    return $x>=0 and $x<30 and $y>=0 and $y<30;
    }



    // it returns 1 if there is a sticky trap on $k ($k=$x+30*$y),
    // 2 if there is a teleport trap on $k, and nothing if there is not a trap on $k

    function trap($w, $r, $k) {
    if (in_array($k, $w['s']) or in_array($k, $r['s'])) return 1;
    if ($k==$w['t'] or $k==$r['t']) return 2;
    }



    // it sets the global var $winner to the text that say that smb wins

    function winner($c, $p) {
    global $winner;
    $winner="<hr /><b><big><font color=".($c=='w'?'black':'red')."> $p[n] WINS!";
    }



    // this is the main logic function... it processes one move from move.txt...

    function process($w, $r, $c, $n, $b, $p, $m) {
    $mx=array('T'=>0, 'U'=>0, 'L'=>-1, 'R'=>+1, 'D'=>0);
    $my=array('T'=>0, 'U'=>-1, 'L'=>0, 'R'=>0, 'D'=>+1);
    switch ($m[0]) {
    case 'M':
    $p['i']='MOVEBAD';
    if (valid($i=$p['x']+$mx[$m[1]], $j=$p['y']+$my[$m[1]])) {
    $p['x']=$i;
    $p['y']=$j;
    $p['i']='MOVEOK';
    if (trap($w, $r, $k=$i+30*$j)==1) $p['i']='STUCK1';
    if (trap($w, $r, $k)==2) {
    $p['x']=rand(0, 29);
    $p['y']=rand(0, 29);
    $p['i']="T$p[x],$p[y]";
    }
    if ($c=='w' and $k==806 or $c=='r' and $k==93) winner($c, $p);
    }
    break;
    case 'R':
    $p['i']='MOVEOK';
    break;
    case 'T':
    $p['i']='TRAPBAD';
    $k=(($i=$p['x']+$mx[$m[1]])+30*($j=$p['y']+$my[$m[1]]));
    if ($m[1]!='T' and valid($i, $j) and !trap($w, $r, $k) and count($p['s'])<7 and $k!=93 and $k!=806) {
    $p['i']='TRAPOK';
    $p['s'][]=$k;
    $b[$k]='yellow';
    }
    if ($m[1]=='T' and valid($i, $j) and !trap($w, $r, $k) and $p['t']==-1 and $k!=93 and $k!=806) {
    $p['i']='TRAPOK';
    $p['t']=$k;
    $b[$k]='blue';
    }
    break;
    case 'L':
    $p['i']='LBAD';
    if ($p['l']<5) {
    $i=$$n;
    $p['i']="L$i[x],$i[y]";
    $p['l']++;
    }
    break;
    case 'D':
    $p['i']='DEATHMISSED';
    if ($p['d']<1) {
    $k=$$n;
    if (!valid(($i=$p['x'])+$mx[$m[1]], ($j=$p['y'])+$my[$m[1]])) winner($n, $$n);
    while (valid($i+=$mx[$m[1]], $j+=$my[$m[1]])) if ($k['x']==$i and $k['y']==$j) winner($c, $p);
    $p['d']++;
    }
    break;
    }
    return array('w'=>$w, 'r'=>$r, 'c'=>$c, 'n'=>$n, 'b'=>$b, 'p'=>$p);
    }



    // this function returns javascript that changes colors on the grid, and moves teams around...

    function grid($b, $f, $p='') {
    foreach ($b as $k=>$v) $p.="parent.grid.document.getElementById('c$k').style.background='$v';\n";
    foreach ($f as $k=>$v) $p.="parent.grid.document.i$k.src='$v.gif';\n";
    return "<script language='javascript'>\n$p\n</script>\n";
    }



    // outputs all the info u see in the right frame, and some controls (check box and a button)

    function control($w, $r, $c, $p, $m) {
    global $winner, $timeOut;
    if ( !isset($timeOut) )$timeOut = 250;
    return "<link href='global.css' rel='stylesheet' type='text/css' /> <form name=forma>
    <input type='checkbox' name=next ".((!isset($_GET['next']) or @$winner)?'':'checked')." /> auto
    <input type=textfield name=timeOut value=$timeOut>Auto Time-out
    <input type='submit' value='next' /></form><hr />\n<script language='javascript'>
    setTimeout('if (document.forma.next.checked) document.forma.submit() ', document.forma.timeOut.value);\n</script>
    <table border=1 cellspacing=1 cellpadding=1 bordercolor=white width='100%'>
    <tr><td class=meta>&nbsp;<td class=white><b>$w[n]<td class=red><b>$r[n]
    <tr><td class=meta>location<td class=white>$w[x],$w[y]<td class=red>$r[x],$r[y]
    <tr><td class=meta>sticky<td class=white>".count($w['s'])."<td class=red>".count($r['s'])."
    <tr><td class=meta>teleport<td class=white>".($w['t']>=0?1:0)."<td class=red>".($r['t']>=0?1:0)."
    <tr><td class=meta>death.ray<td class=white>$w[d]<td class=red>$r[d]
    <tr><td class=meta>locators<td class=white>$w[l]<td class=red>$r[l]
    <tr><td class=meta>move.txt<td class=white>".($c=='w'?$m:'.')."<td class=red>".($c=='r'?$m:'.')."
    <tr><td class=meta>input.txt<td colspan=2 class=".($c=='w'?'white':'red').">$p[i]</table>".(@$winner);
    }



    // main() function ;))

    function main() {
    if (isset($_POST['white'])) {
    extract(start($_POST['white'], $_POST['red']));
    } else {
    extract(unserialize(fread(fopen('data.txt', 'r'), 999)));
    }
    $n=(($c=='w')?'r':'w');
    $p=$$c;
    if ($p['i']=='STUCK1') {
    $p['i']='STUCK';
    $$c=$p;
    $m='??';
    } else {
    chdir($p['n']);
    fwrite(fopen('input.txt', 'w'), "$p[i]\n");
    run();
    $m=fread(fopen('move.txt', 'r'), 99);
    chdir("..");
    $i=array('w'=>$w['x']+30*$w['y'], 'r'=>$r['x']+30*$r['y']);
    extract(process($w, $r, $c, $n, $b, $p, $m));
    $$c=$p;
    $f=array($i['w']=>'blank', $i['r']=>'blank', $w['x']+30*$w['y']=>'white', $r['x']+30*$r['y']=>'red');
    echo grid($b, $f);
    }
    echo control($w, $r, $c, $$c, $m);
    fwrite(fopen('data.txt', 'w'), serialize(array('w'=>$w, 'r'=>$r, 'c'=>$n, 'b'=>array())));
    }

    main();

    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Contest Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Trial download: IBM Rational Performance Tester V7.0.1

    Get a free trial download of the latest version of IBM Rational Performance Tester V7.0.1, a load and performance testing solution for teams concerned about the scalability of their Web-based applications. Combining multiple ease-of-use features with granular detail, Rational Performance Tester simplifies the test-creation, load-generation and data-collection processes that help teams ensure the ability of their applications to accommodate required user loads.
    FREE! Go There Now!


    NEW! Evaluate IBM Rational Software Analyzer V7.0

    Download a free trial version of IBM Rational Software Analyzer Developer Edition V7.0 to identify bug defects earlier in the software development cycle. Rational Software Analyzer is an extensible software development solution that reduces the expense of bug-fixes by enabling static analysis code reviews and bug identification very early in the development cycle.
    FREE! Go There Now!


    NEW! Evaluate Rational Business Developer V7.1

    Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities.
    FREE! Go There Now!


    NEW! Develop Systems Software Assets with IBM Rational Asset Manager

    Join us for this on demand webcast to learn about developing complex systems more quickly and efficiently. We'll cover market drivers for developing, governing and reusing systems software assets and how you can develop system software assets with Rational Asset Manager.
    FREE! Go There Now!


    NEW! Webcast: Accelerating Software Innovation with System z

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    NEW! Applying lean thinking to the governance of software development

    Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations.
    FREE! Go There Now!


    NEW! Webcast: Application security testing and Web compliance

    Join the IBM Watchfire team for an informative discussion on techniques and best practices to proactively manage Web application security and how to effectively build application security testing into the software development lifecycle (SDLC). In this Software Delivery Platform webcast you will learn: How to better understand potential web application security vulnerabilities, best practices and how to effectively integrate application security testing into the software development lifecycle, the importance of detecting and removing software vulnerabilities during application development.
    FREE! Go There Now!


    NEW! Whitepaper: Achieving consistency between business process models and operational guides

    Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise.
    FREE! Go There Now!


    Role of Integrated Requirements Management in Software Delivery

    As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change.
    FREE! Go There Now!


    NEW! Trial download: IBM Lotus Forms V3.0

    Get a free trial download of IBM Lotus Forms V3.0 (formerly Workplace Forms), which provides a zero-footprint eForms solution to help you automate and move forms-based business processes off the desktop and onto the Web. With Lotus Forms, you can extend applications beyond the firewall by creating a single electronic form document ready for use in both thick and Web 2.0 thin client format.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    CONTEST CODE ARTICLES

    - Visual Map Editor And Generator
    - Corridors map generator
    - PHP-JAVA Class Code Generator
    - Risk - print_map($game, $some_array_of_size_...
    - Risk: The Original ShowGame/Map
    - Showgame2
    - Risk map output
    - CTF-Judge, better "auto" controls
    - Capture The Flag -- The JUDGE





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT