summaryrefslogtreecommitdiffstats
path: root/test/cbot
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2013-02-03 20:03:36 +0100
committerPiotr Dziwinski <piotrdz@gmail.com>2013-02-03 20:03:36 +0100
commit209c6412ae149cc7c503fd7da384f344a830423c (patch)
tree5baeaeb8dee2208b46bf80a118dfe59eb65f9389 /test/cbot
parent3f41f97fc47fca22634dc858c3ecdb39d0d27e32 (diff)
downloadcolobot-209c6412ae149cc7c503fd7da384f344a830423c.tar.gz
colobot-209c6412ae149cc7c503fd7da384f344a830423c.tar.bz2
colobot-209c6412ae149cc7c503fd7da384f344a830423c.zip
Refactoring in tests infrastructure
* all tests are now in /test/ subdirectory * unit tests concatenated to one executable (TODO: ui, common) * preparation for test environments (OpenGL and others) * removed old TestCBot
Diffstat (limited to 'test/cbot')
-rw-r--r--test/cbot/CBot_console/CBotConsole.cpp175
-rw-r--r--test/cbot/CBot_console/CBotConsole.h44
-rw-r--r--test/cbot/CBot_console/CBotDoc.cpp122
-rw-r--r--test/cbot/CBot_console/CBotDoc.h39
-rw-r--r--test/cbot/CBot_console/CClass.cpp97
-rw-r--r--test/cbot/CBot_console/CClass.h18
-rw-r--r--test/cbot/CBot_console/CMakeLists.txt16
-rw-r--r--test/cbot/CBot_console/main.cpp45
-rw-r--r--test/cbot/CBot_console/routines.cpp141
-rw-r--r--test/cbot/CMakeLists.txt2
-rw-r--r--test/cbot/scenarios/B.txt18
-rw-r--r--test/cbot/scenarios/BUG2.txt107
-rw-r--r--test/cbot/scenarios/Deleted.txt23
-rw-r--r--test/cbot/scenarios/MaClass.txt16
-rw-r--r--test/cbot/scenarios/Mc2.txt4
-rw-r--r--test/cbot/scenarios/Mon fichier.txt2
-rw-r--r--test/cbot/scenarios/Nop.txt4
-rw-r--r--test/cbot/scenarios/POS.txt14
-rw-r--r--test/cbot/scenarios/T.txt4
-rw-r--r--test/cbot/scenarios/TESTALL.txt161
-rw-r--r--test/cbot/scenarios/TestCB1.txt18
-rw-r--r--test/cbot/scenarios/TestCBot1.txt27
-rw-r--r--test/cbot/scenarios/TestCBot3.txt24
-rw-r--r--test/cbot/scenarios/TestNull.txt15
-rw-r--r--test/cbot/scenarios/TestRestoreState.txt67
-rw-r--r--test/cbot/scenarios/TestStatic.txt31
-rw-r--r--test/cbot/scenarios/TestStr.txt17
-rw-r--r--test/cbot/scenarios/Z.txt14
-rw-r--r--test/cbot/scenarios/a.txt312
-rw-r--r--test/cbot/scenarios/bug.txt12
-rw-r--r--test/cbot/scenarios/bugmw.txt9
-rw-r--r--test/cbot/scenarios/ccc.txt8
-rw-r--r--test/cbot/scenarios/enum.txt9
-rw-r--r--test/cbot/scenarios/fibo.txt25
-rw-r--r--test/cbot/scenarios/file.txt70
-rw-r--r--test/cbot/scenarios/h.txt5
-rw-r--r--test/cbot/scenarios/include.txt27
-rw-r--r--test/cbot/scenarios/intrinsic.txt16
-rw-r--r--test/cbot/scenarios/methode1.txt57
-rw-r--r--test/cbot/scenarios/methode2.txt50
-rw-r--r--test/cbot/scenarios/mp1.txt25
-rw-r--r--test/cbot/scenarios/mp2.txt28
-rw-r--r--test/cbot/scenarios/mw.txt16
-rw-r--r--test/cbot/scenarios/null.txt5
-rw-r--r--test/cbot/scenarios/opnew.txt20
-rw-r--r--test/cbot/scenarios/plante.txt25
-rw-r--r--test/cbot/scenarios/pointer.txt41
-rw-r--r--test/cbot/scenarios/postinc.txt7
-rw-r--r--test/cbot/scenarios/radar.txt39
-rw-r--r--test/cbot/scenarios/solution.txt13
-rw-r--r--test/cbot/scenarios/test.txt8
-rw-r--r--test/cbot/scenarios/test23.txt10
-rw-r--r--test/cbot/scenarios/testmw.txt14
-rw-r--r--test/cbot/scenarios/this.txt13
-rw-r--r--test/cbot/scenarios/tt.txt12
-rw-r--r--test/cbot/scenarios/tt2.txt5
-rw-r--r--test/cbot/scenarios/vide.txt0
-rw-r--r--test/cbot/scenarios/zz.txt6
58 files changed, 2152 insertions, 0 deletions
diff --git a/test/cbot/CBot_console/CBotConsole.cpp b/test/cbot/CBot_console/CBotConsole.cpp
new file mode 100644
index 0000000..e9209d3
--- /dev/null
+++ b/test/cbot/CBot_console/CBotConsole.cpp
@@ -0,0 +1,175 @@
+/*
+ * CBotConsole.cpp
+ *
+ * Created on: 08-08-2012
+ * Author: michal
+ */
+
+#include "CBotConsole.h"
+#include "CClass.h"
+#include <ctime>
+#include <iostream>
+
+CBotConsole::CBotConsole() {
+ // TODO Auto-generated constructor stub
+ m_pProg = NULL;
+ m_threadinfo.m_bRun = false;
+ m_code = 0;
+
+}
+
+CBotConsole::~CBotConsole() {
+ // TODO Auto-generated destructor stub
+}
+
+uint ThreadProc(ThreadInfo *info)
+{
+ time_t t0,t1;
+ time(&t0);
+
+ int Cpt = 0;
+
+ info->m_pProg->Start("LaCommande");
+ while ( !info->m_bStop && !info->m_pProg->Run() )
+ {
+#if 0
+ const char* FunctionName;
+ const char* FN;
+ int start, end;
+
+ info->m_pProg->GetRunPos(FunctionName, start, end);
+
+ if ( FunctionName != NULL )
+ {
+ info->m_pEditx->SetSel(start, end);
+
+ char buffer[200];
+ sprintf( buffer, "step %s, %d, %d",FunctionName, start, end);
+ AfxMessageBox( buffer );
+
+ int level = 0;
+ do
+ {
+ CBotVar* t = info->m_pProg->GetStackVars(FN, level--);
+ if ( FN != FunctionName ) break;
+ if ( t != NULL )
+ {
+ CString s ;
+ while ( t != NULL )
+ {
+ if (s.IsEmpty()) s+= "Stack -> ";
+ else s+= " , ";
+ s += t->GetValString();
+ t = t->GetNext();
+ }
+ AfxMessageBox(s);
+ }
+ } while (TRUE);
+ }
+#endif
+ Cpt++;
+ if ( Cpt%50 == 0 ) std::cout << ".";
+ }
+
+ if ( info->m_bStop )
+ {
+ std::cout << "\nInterrupt\n";
+ }
+ else if (info->m_pProg->GetError() == 0)
+ {
+ time(&t1);
+ double prog_time = difftime(t0,t1);
+
+ char buffer[200];
+ sprintf( buffer, "\nExecution terminated in %f seconds.\nInterrupted %d time(s).\n",
+ prog_time, Cpt);
+
+ std::cout << buffer;
+ }
+
+// info->m_pWndMessage->SendMessage(WM_ENDPROG, 0, 0) ;
+ return 0 ;
+}
+
+long CBotConsole::EndProg()
+{
+ m_threadinfo.m_bRun = false;
+
+ if (m_pProg->GetError(m_code, m_start, m_end))
+ {
+ CBotString TextError;
+ TextError = CBotProgram::GetErrorText(m_code);
+ std::cout << TextError;
+ return 1;
+ }
+ delete m_pProg;
+ m_pProg = NULL;
+
+ return 0 ;
+}
+
+
+void CBotConsole::OnOK()
+{
+ m_code = 0;
+
+ std::string Commande;
+ std::cin >> Commande;
+
+ std::string s = "void LaCommande() { " + Commande + " ;}";
+ m_pProg = new CBotProgram();
+ CBotStringArray liste;
+ m_pProg->Compile(s.c_str(), liste);
+
+ int err, start, end;
+ if ( m_pProg->GetError(err, start, end) )
+ {
+ CBotString TextError;
+ TextError = CBotProgram::GetErrorText(err);
+ std::cout << TextError;
+ return;
+ }
+
+ std::cout << "\n" + Commande + " ->\n";
+
+// m_Edit2.SetWindowText("");
+// m_Edit1.SetFocus();
+// m_Edit2.EnableWindow(FALSE);
+// m_cOK.EnableWindow(FALSE);
+
+ // lance un processus paralèle pour l'exécution
+// m_threadinfo.m_pWndMessage = this ;
+
+// m_threadinfo.m_pEdit1 = &m_Edit1;
+// m_threadinfo.m_pEditx = m_pEditx;
+ m_threadinfo.m_pProg = m_pProg;
+ m_threadinfo.m_bStop = false;
+ m_threadinfo.m_bRun = true;
+
+ ThreadProc(&m_threadinfo);
+
+// here program starts
+// AfxBeginThread((AFX_THREADPROC)ThreadProc, &m_threadinfo) ;
+}
+
+void CBotConsole::OnCancel()
+{
+ m_threadinfo.m_bStop = true ;
+}
+
+bool CBotConsole::OnInitDialog()
+{
+// CDialog::OnInitDialog();
+
+ std::cout << "Following functions are availible:\n";
+ for ( int i = 0; i < m_pListe->GetSize(); i++ )
+ {
+ CBotString x = (*m_pListe)[i] + CBotString("\n");
+ std::cout << x;
+ }
+ std::cout << "Enter a command:\n";
+
+
+ return true; // return TRUE unless you set the focus to a control
+ // EXCEPTION: OCX Property Pages should return FALSE
+}
diff --git a/test/cbot/CBot_console/CBotConsole.h b/test/cbot/CBot_console/CBotConsole.h
new file mode 100644
index 0000000..a155399
--- /dev/null
+++ b/test/cbot/CBot_console/CBotConsole.h
@@ -0,0 +1,44 @@
+/*
+ * CBotConsole.h
+ *
+ * Created on: 08-08-2012
+ * Author: michal
+ */
+
+#ifndef CBOTCONSOLE_H_
+#define CBOTCONSOLE_H_
+#include "CClass.h"
+
+struct ThreadInfo
+{
+// CEdit* m_pEdit1 ;
+// CEdit* m_pEditx ;
+ CBotProgram* m_pProg;
+// CWnd* m_pWndMessage;
+ bool m_bStop;
+ bool m_bRun;
+};
+
+class CBotConsole {
+
+public:
+ CBotConsole();
+ virtual ~CBotConsole();
+
+// CEdit m_Edit1;
+
+ CBotProgram* m_pProg;
+ ThreadInfo m_threadinfo;
+
+ CBotStringArray* m_pListe;
+ int m_code, m_start, m_end;
+// CEdit* m_pEditx;
+
+ // Implementation
+ void OnOK();
+ void OnCancel();
+ bool OnInitDialog();
+ long EndProg() ;
+};
+
+#endif /* CBOTCONSOLE_H_ */
diff --git a/test/cbot/CBot_console/CBotDoc.cpp b/test/cbot/CBot_console/CBotDoc.cpp
new file mode 100644
index 0000000..1c694c9
--- /dev/null
+++ b/test/cbot/CBot_console/CBotDoc.cpp
@@ -0,0 +1,122 @@
+/*
+ * CBotDoc.cpp
+ *
+ * Created on: 08-08-2012
+ * Author: michal
+ */
+#include "CBotDoc.h"
+#include "CBotConsole.h"
+#include <iostream>
+
+CBotDoc::CBotDoc(std::string s) {
+ // TODO Auto-generated constructor stub
+ // TODO set m_DocText
+// m_pEdit = NULL;
+ m_pProg = NULL;
+// m_bModified = FALSE;
+ m_DocText = s;
+ std::cout << s << std::endl;
+// std::cout << "Enter to continue..." << std::endl;
+// getchar();
+}
+
+CBotDoc::~CBotDoc() {
+
+// delete m_pEdit;
+ delete m_pProg;
+}
+
+
+//static bool test = false;
+
+void CBotDoc::OnRun()
+{
+
+// m_pEdit->GetWindowText(m_DocText);
+ CBotString s;
+
+ std::string TextError;
+ int code, start, end;
+
+ if ( m_pProg == NULL ) m_pProg = new CBotProgram();
+
+ if (!m_pProg->Compile(m_DocText.c_str(), m_Liste, NULL))
+ {
+ m_pProg->GetError(code, start, end);
+ delete m_pProg;
+ m_pProg = NULL;
+
+ TextError = CBotProgram::GetErrorText( code );
+ std::cout << TextError << std::endl;
+ return;
+ }
+
+ if( m_Liste.GetSize() == 0 )
+ {
+ std::cout << "No function marked \"extern\" !\n";
+ return;
+ }
+
+ for ( int i = 0; i < m_Liste.GetSize(); i++ )
+ {
+ int start, stop;
+ m_pProg->GetPosition(m_Liste[i], start, stop, GetPosNom, GetPosParam);
+ CBotString s(m_DocText.substr( start, stop-start ).c_str());
+ m_Liste[i] = s;
+ }
+// TODO
+ CBotConsole dlg;
+ dlg.m_pListe = &m_Liste;
+// dlg.m_pEditx = m_pEdit;
+
+ dlg.OnInitDialog();
+ dlg.OnOK();
+ dlg.EndProg();
+// if ( dlg.m_code>0 )
+// {
+// std::string TextError;
+//
+// TextError = m_pProg->GetErrorText( dlg.m_code );
+//
+// std::cout <<TextError;
+// }
+
+ return;
+}
+
+bool CBotDoc::Compile()
+{
+// m_pEdit->GetWindowText(m_DocText);
+
+ std::string TextError;
+ int code, start, end;
+
+ if ( m_pProg == NULL ) m_pProg = new CBotProgram();
+
+ char buffer[100];
+ strcpy(buffer, "a pointer move to see");
+
+ if (!m_pProg->Compile(m_DocText.c_str(), m_Liste, static_cast<void*>(buffer)))
+ {
+ m_pProg->GetError(code, start, end);
+ delete m_pProg;
+ m_pProg = NULL;
+
+// m_pEdit->SetSel( start, end );
+// m_pEdit->SetFocus(); // higlights part of problem
+
+ TextError = CBotProgram::GetErrorText( code );
+ std::cout << TextError ;
+
+ return false;
+ }
+
+// if ( m_pProg->GetPosition( "TheTest", start, end) )
+// {
+// m_pEdit->SetSel( start, end );
+// m_pEdit->SetFocus(); // higlights part of problem
+// }
+
+// m_bModified = FALSE;
+ return true;
+}
diff --git a/test/cbot/CBot_console/CBotDoc.h b/test/cbot/CBot_console/CBotDoc.h
new file mode 100644
index 0000000..c0a3e1d
--- /dev/null
+++ b/test/cbot/CBot_console/CBotDoc.h
@@ -0,0 +1,39 @@
+/*
+ * CBotDoc.h
+ *
+ * Created on: 08-08-2012
+ * Author: michal
+ */
+
+#pragma once
+#ifndef CBOTDOC_H_
+#define CBOTDOC_H_
+
+#include "CClass.h"
+#include <string>
+
+class CBotDoc {
+
+public:
+ CBotDoc(std::string);
+ virtual ~CBotDoc();
+
+// CEdit* m_pEdit; // to memorize the text, and display
+ CBotProgram* m_pProg; // the compiled program
+ std::string m_DocText;
+ CBotStringArray m_Liste;
+
+// Operations
+
+ bool Compile();
+
+// virtual bool OnNewDocument();
+
+ void OnRun();
+ void OnChangeEdit1();
+ void OnTest();
+
+};
+
+
+#endif /* CBOTDOC_H_ */
diff --git a/test/cbot/CBot_console/CClass.cpp b/test/cbot/CBot_console/CClass.cpp
new file mode 100644
index 0000000..9b7c842
--- /dev/null
+++ b/test/cbot/CBot_console/CClass.cpp
@@ -0,0 +1,97 @@
+#include "CClass.h"
+
+#include "routines.cpp"
+
+void rMajObject( CBotVar* pThis, void* pUser )
+{
+ if (!pThis->IsElemOfClass("object"))
+ return ;
+ CBotVar* pPos = pThis->GetItem("position");
+ CBotVar* pX = pPos->GetItem("x");
+ CBotVar* pY = pPos->GetItem("y");
+ CBotVar* pZ = pPos->GetItem("z");
+// CBotVar* pPt = pThis->GetItem("transport");
+
+ CBotString p = pX->GetValString();
+
+// pX->SetValFloat( pUser == (void*)1 ? (float)12.5 : (float)44.4 );
+ pZ->SetValFloat( (float)0 );
+ pY->SetValFloat( (float)-3.33 );
+ pX->SetValFloat( pX->GetValFloat() + 10 ) ;
+
+// pX = pThis->GetItem( "xx" );
+// pX->SetValFloat( (float)22 );
+
+ // crée une instance sur une classe object
+// CBotVar* pAutre = CBotVar::Create("autre", CBotTypClass, "object");
+// pAutre->SetUserPtr( (void*)3 );
+// pPt->SetPointer( pAutre );
+// pPt->SetPointer( NULL );
+// delete pAutre;
+};
+
+CClass::CClass()
+{
+ m_pClassPoint= NULL;
+}
+
+bool CClass::InitInstance()
+{
+//////////////////////////////////////////////
+// défini les mots clefs supplémentaires
+// -------------------------------------------
+
+ CBotProgram::Init();
+
+//////////////////////////////////////////////
+// défini les fonctions "show()" et "print()"
+// -------------------------------------------
+
+ //CBotProgram::AddFunction("show", rShow, cShow);
+ CBotProgram::AddFunction("print", rPrint, cPrint);
+ CBotProgram::AddFunction("println", rPrintLn, cPrint);
+
+
+///////////////////////////////////
+// définie la classe globale CPoint
+// --------------------------------
+
+ m_pClassPoint = new CBotClass("CPoint", NULL);
+ // ajoute le composant ".x"
+ m_pClassPoint->AddItem("x", CBotTypFloat);
+ // ajoute le composant ".y"
+ m_pClassPoint->AddItem("y", CBotTypFloat);
+
+ // ajoute le constructeur pour cette classe
+ m_pClassPoint->AddFunction("CPoint", rCPoint, cCPoint);
+
+ m_pClassPointIntr = new CBotClass("point", NULL, true);
+ // ajoute le composant ".x"
+ m_pClassPointIntr->AddItem("x", CBotTypFloat);
+ // ajoute le composant ".y"
+ m_pClassPointIntr->AddItem("y", CBotTypFloat);
+ // ajoute le composant ".z"
+ m_pClassPointIntr->AddItem("z", CBotTypFloat);
+
+ // ajoute le constructeur pour cette classe
+ m_pClassPointIntr->AddFunction("point", rCPoint, cCPoint);
+
+ // défini la classe "object"
+ CBotClass* pClassObject = new CBotClass( "object", NULL ) ;
+ pClassObject->AddItem( "xx", CBotTypFloat );
+ pClassObject->AddItem( "position", CBotTypResult( CBotTypIntrinsic, "point" ) );
+ pClassObject->AddItem( "transport", CBotTypResult( CBotTypPointer, "object" ) );
+ pClassObject->AddUpdateFunc( rMajObject );
+
+ InitClassFILE();
+
+ return true;
+}
+
+void CClass::ExitInstance()
+{
+ delete m_pFuncFile;
+
+ CBotProgram::Free();
+
+}
diff --git a/test/cbot/CBot_console/CClass.h b/test/cbot/CBot_console/CClass.h
new file mode 100644
index 0000000..da2c46c
--- /dev/null
+++ b/test/cbot/CBot_console/CClass.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <CBot/CBot.h>
+#include <string>
+
+extern std::string s;
+
+class CClass
+{
+public:
+ CClass();
+
+ CBotClass* m_pClassPoint;
+ CBotClass* m_pClassPointIntr;
+
+ bool InitInstance();
+ void ExitInstance();
+};
diff --git a/test/cbot/CBot_console/CMakeLists.txt b/test/cbot/CBot_console/CMakeLists.txt
new file mode 100644
index 0000000..5016a77
--- /dev/null
+++ b/test/cbot/CBot_console/CMakeLists.txt
@@ -0,0 +1,16 @@
+set(SOURCES
+CClass.cpp
+main.cpp
+CBotDoc.cpp
+CBotConsole.cpp
+)
+
+set(LIBS
+CBot
+)
+
+include_directories(${colobot_SOURCE_DIR}/src)
+
+add_executable(CBot_console ${SOURCES})
+
+target_link_libraries(CBot_console ${LIBS})
diff --git a/test/cbot/CBot_console/main.cpp b/test/cbot/CBot_console/main.cpp
new file mode 100644
index 0000000..a2d3668
--- /dev/null
+++ b/test/cbot/CBot_console/main.cpp
@@ -0,0 +1,45 @@
+#include "CClass.h"
+#include "CBotDoc.h"
+#include <iostream>
+
+
+#include <fstream>
+
+std::string str;
+
+// routine to update the instance of the class Bot common
+
+int main(int argc, char* argv[])
+{
+ CClass newclass;
+ CBotDoc *botdoc;
+ if (argc != 2)
+ {
+ std::cout << "Usage: "<<argv[0] << " <filename>" << std::endl;
+ return 0;
+ }
+
+ std::ifstream in(argv[1]);
+ std::cout << argv[1] << std::endl;
+ if (!in.good())
+ {
+ std::cout << "Oh no, error!" << std::endl;
+ return 1;
+ }
+
+ std::string contents((std::istreambuf_iterator<char>(in)),
+ std::istreambuf_iterator<char>());
+ str = contents;
+
+ if(!newclass.InitInstance())
+ {
+ std::cerr << "Initialization not complete!" << std::endl;
+ return 1;
+ }
+
+ botdoc = new CBotDoc(str);
+// std::cout << "Hello CBot!" << std::endl << s;
+ botdoc->OnRun();
+ delete botdoc;
+ newclass.ExitInstance();
+}
diff --git a/test/cbot/CBot_console/routines.cpp b/test/cbot/CBot_console/routines.cpp
new file mode 100644
index 0000000..8b8a1d4
--- /dev/null
+++ b/test/cbot/CBot_console/routines.cpp
@@ -0,0 +1,141 @@
+// * This file is part of the COLOBOT source code
+// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
+// *
+// * This program is free software: you can redistribute it and/or modify
+// * it under the terms of the GNU General Public License as published by
+// * the Free Software Foundation, either version 3 of the License, or
+// * (at your option) any later version.
+// *
+// * This program is distributed in the hope that it will be useful,
+// * but 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.
+// *
+// * You should have received a copy of the GNU General Public License
+// * along with this program. If not, see http://www.gnu.org/licenses/.
+
+////////////////////////////////////////////////////////////////////
+// routine show()
+// utilisable depuis le programme écrit en CBot
+
+
+#include <iostream>
+#include <string>
+#include "CBot/ClassFILE.cpp"
+//std::string s;
+/*
+// execution
+bool rShow( CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser )
+{
+ string::string s;
+
+ while ( pVar != NULL )
+ {
+ string::string ss;
+
+ ss.LoadString( TX_TYPENAMES + pVar->GetType() );
+ s += ss + " ";
+
+ ss = pVar->GetName();
+ if (ss.IsEmpty()) ss = "<sans nom>";
+ s += ss + " = ";
+
+ s += pVar->GetValString();
+ s += "\n";
+ pVar = pVar->GetNext();
+ }
+
+ AfxMessageBox(s, MB_OK|MB_ICONINFORMATION);
+
+ return TRUE; // pas d'interruption
+}
+
+CBotTypResult cShow( CBotVar* &pVar, void* pUser)
+{
+ if ( pVar == NULL ) return CBotTypResult(5028);
+ return CBotTypResult(0); // tous paramètres acceptés, void en retour
+}
+
+*/
+
+////////////////////////////////////////////////////////////////////
+// routine print()
+// utilisable depuis le programme écrit en CBot
+
+// exécution
+
+bool rPrintLn( CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser )
+{
+ std::string s;
+ while ( pVar != NULL )
+ {
+ if ( !s.empty() ) s += " ";
+ s += pVar->GetValString();
+ pVar = pVar->GetNext();
+ }
+ s += "\n";
+
+ std::cout << s;
+ return true; // pas d'interruption
+}
+
+bool rPrint( CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser )
+{
+ std::string s;
+ while ( pVar != NULL )
+ {
+ if ( !s.empty() ) s += " ";
+ s += pVar->GetValString();
+ pVar = pVar->GetNext();
+ }
+ s += " ";
+ std::cout << s;
+ return true; // pas d'interruption
+}
+
+CBotTypResult cPrint( CBotVar* &pVar, void* pUser)
+{
+ return CBotTypResult(0); // tous paramètres acceptés, un entier en retour
+}
+
+
+//////////////////////////////////////////////////////////////////
+// class CPoint pour essayer
+
+// exécution
+bool rCPoint( CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception )
+{
+ if ( pVar == NULL )return true; // constructor with no parameters is ok
+
+ CBotVar* pX = pThis->GetItem("x");
+ pX->SetValFloat( pVar->GetValFloat() );
+ pVar = pVar->GetNext();
+
+ CBotVar* pY = pThis->GetItem("y");
+ pY->SetValFloat( pVar->GetValFloat() );
+ pVar = pVar->GetNext();
+
+ return true; // pas d'interruption
+}
+
+CBotTypResult cCPoint( CBotVar* pThis, CBotVar* &pVar)
+{
+ // ok if no parameters!
+ if ( pVar == NULL ) return CBotTypResult(0);
+
+ // numeric type of parameter please
+ if ( pVar->GetType() > CBotTypDouble ) return CBotTypResult(5011);
+ pVar = pVar->GetNext();
+
+ // there must be a second parameter
+ if ( pVar == NULL ) return 5028;
+ // also numeric
+ if ( pVar->GetType() > CBotTypDouble )return CBotTypResult(5011);
+ pVar = pVar->GetNext();
+
+ // and not more than 2 parameters please
+ if ( pVar != NULL ) return CBotTypResult(5026);
+
+ return CBotTypResult(0); // This function returns void
+}
+
diff --git a/test/cbot/CMakeLists.txt b/test/cbot/CMakeLists.txt
new file mode 100644
index 0000000..e864ed5
--- /dev/null
+++ b/test/cbot/CMakeLists.txt
@@ -0,0 +1,2 @@
+# CBot console interpreter
+add_subdirectory(CBot_console)
diff --git a/test/cbot/scenarios/B.txt b/test/cbot/scenarios/B.txt
new file mode 100644
index 0000000..53715f8
--- /dev/null
+++ b/test/cbot/scenarios/B.txt
@@ -0,0 +1,18 @@
+
+ float [ ] TEST2 ( int [ ] param )
+ {
+ float [ ] z;
+ for ( int i = 0 ; i < sizeof( param ) ; i++ ) try { z [i] = param [i] / 3; }
+ return z;
+ }
+
+extern public void T()
+{
+ int a [4];
+ for ( int i = 0 ; i < 3 ; i++ ) a[i] = 4*i;
+ a [2] = 22;
+
+ float [] b ;
+ b = TEST2 ( a ) ;
+ show ( a, b );
+}
diff --git a/test/cbot/scenarios/BUG2.txt b/test/cbot/scenarios/BUG2.txt
new file mode 100644
index 0000000..44de05a
--- /dev/null
+++ b/test/cbot/scenarios/BUG2.txt
@@ -0,0 +1,107 @@
+object object :: TT ( int n )
+{
+ object XX = radar();
+ if ( n == 0 ) return null;
+
+ while ( null == XX ) XX = radar();
+ return XX;
+}
+
+extern void object::Attack( )
+{
+ show ( TT ( 0 ) ) ;
+ show ( TT ( 1 ) ) ;
+ return;
+
+ int list[];
+ int i;
+ object p;
+ float dist, prox;
+ point dest;
+ boolean advance = true;
+
+ TEST(0); // ne stoppe pas si erreur
+// while ( F () != 0 ) F(1);
+
+ i = 0;
+ list[i++] = WingedGrabber;
+ list[i++] = TrackedGrabber;
+ list[i++] = WheeledGrabber;
+ list[i++] = LeggedGrabber;
+ list[i++] = WingedShooter;
+ list[i++] = TrackedShooter;
+ list[i++] = WheeledShooter;
+ list[i++] = LeggedShooter;
+ list[i++] = WingedOrgaShooter;
+ list[i++] = TrackedOrgaShooter;
+ list[i++] = WheeledOrgaShooter;
+ list[i++] = LeggedOrgaShooter;
+ list[i++] = WingedSniffer;
+ list[i++] = TrackedSniffer;
+ list[i++] = WheeledSniffer;
+ list[i++] = LeggedSniffer;
+ list[i++] = Thumper;
+ list[i++] = PhazerShooter;
+ list[i++] = Recycler;
+ list[i++] = Shielder;
+ list[i++] = Subber;
+ list[i++] = Me;
+ list[i++] = 3333;
+ list[i++] = 3334;
+ list[i++] = 3335;
+ list[i++] = 3336;
+ list[i++] = 3337;
+ list[i++] = 3338;
+ list[i++] = 3339;
+ list[i++] = 3331;
+ list[i++] = 3332;
+ list[i++] = 3330;
+ list[i++] = 1111;
+ list[i++] = 1112;
+
+ F(F(0));
+
+ while ( true )
+ {
+ p = radar(list, 0, 360, 0, 1000);
+ if ( p == null )
+ {
+ F(2);
+ }
+ else
+ {
+ dist = F(p.position, position);
+ if ( dist <= 40 && !advance )
+ {
+ fire(p.position);
+ advance = true;
+ }
+ else
+ {
+//? if ( RetBaseDistance() > 20 )
+ {
+ prox = dist-(5+F()*5);
+ if ( prox < 5 ) prox = 5;
+ dest.x = (position.x-p.position.x)*prox/dist + p.position.x;
+ dest.y = (position.y-p.position.y)*prox/dist + p.position.y;
+ dest.z = (position.z-p.position.z)*prox/dist + p.position.z;
+ goto(dest);
+ advance = false;
+ }
+ }
+ }
+ }
+}
+
+// Calcule la distance jusqu'à la base.
+
+float object::RetBaseDistance()
+{
+ object p;
+ float dist;
+
+ p = radar(4444, 0, 360, 0, 1000);
+ if ( p == null ) return 1000;
+ dist = F(p.position, position);
+ return dist;
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/Deleted.txt b/test/cbot/scenarios/Deleted.txt
new file mode 100644
index 0000000..469a624
--- /dev/null
+++ b/test/cbot/scenarios/Deleted.txt
@@ -0,0 +1,23 @@
+public extern void object :: ESSAI()
+{
+ while(true)
+ {
+ if ( true )
+ {
+ goto(12);
+ break;
+ }
+ }
+ object x = null ;
+
+ while ( x == null ) x = radar();
+
+ show ( x.position ) ;
+
+ TEST(5, x);
+
+ if ( x == null ) show ( "DELETED" );
+
+ show ( x.position ) ;
+
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/MaClass.txt b/test/cbot/scenarios/MaClass.txt
new file mode 100644
index 0000000..ac472b4
--- /dev/null
+++ b/test/cbot/scenarios/MaClass.txt
@@ -0,0 +1,16 @@
+
+class MaClass
+{
+ int a = 1 ;
+ MaClass pointeur ;
+ MaClass next = null ;
+ CPoint autre = new CPoint( 1 , 1 ) ;
+}
+
+extern public void Test ( )
+{
+ MaClass x () ;
+ x.next = new MaClass ( ) ;
+ println ( x ) ;
+}
+
diff --git a/test/cbot/scenarios/Mc2.txt b/test/cbot/scenarios/Mc2.txt
new file mode 100644
index 0000000..172c259
--- /dev/null
+++ b/test/cbot/scenarios/Mc2.txt
@@ -0,0 +1,4 @@
+class MaClass
+{
+ int t = 12;
+}
diff --git a/test/cbot/scenarios/Mon fichier.txt b/test/cbot/scenarios/Mon fichier.txt
new file mode 100644
index 0000000..6b35bf8
--- /dev/null
+++ b/test/cbot/scenarios/Mon fichier.txt
@@ -0,0 +1,2 @@
+Voici encore du texte
+et une seconde ligne
diff --git a/test/cbot/scenarios/Nop.txt b/test/cbot/scenarios/Nop.txt
new file mode 100644
index 0000000..6a66f6f
--- /dev/null
+++ b/test/cbot/scenarios/Nop.txt
@@ -0,0 +1,4 @@
+public extern void Nop()
+{
+ while ( true ) {}
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/POS.txt b/test/cbot/scenarios/POS.txt
new file mode 100644
index 0000000..688e4fb
--- /dev/null
+++ b/test/cbot/scenarios/POS.txt
@@ -0,0 +1,14 @@
+void object :: T ( )
+{
+ show ( position ) ;
+}
+
+public extern void object :: POS()
+{
+ for ( int i = 0; i < 10 ; i++ )
+ {
+ if ( i == 2 ) TEST ( 12 ) ;
+// show ( position );
+ T ( ) ;
+ }
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/T.txt b/test/cbot/scenarios/T.txt
new file mode 100644
index 0000000..50a792b
--- /dev/null
+++ b/test/cbot/scenarios/T.txt
@@ -0,0 +1,4 @@
+public extern int T ( float n )
+{
+ return n * 1.1;
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/TESTALL.txt b/test/cbot/scenarios/TESTALL.txt
new file mode 100644
index 0000000..82247a0
--- /dev/null
+++ b/test/cbot/scenarios/TESTALL.txt
@@ -0,0 +1,161 @@
+int T ( int z )
+{
+ return 45 + z ;
+}
+
+class toto
+{
+ int val = 3 ;
+ int x = 3 * 3 ;
+ void toto( int n )
+ { val = n + 3 ; }
+ int retval ( int param )
+ { int r = val + param + x ;
+ val = param ;
+ return r ; }
+}
+
+public extern void object :: Chose( )
+{
+ int z [ 6 ];
+ for ( int i = 0 ; i < 6 ; ) z [ i++ ] = 3 - i ;
+ show ( z ) ;
+ return;
+
+ // test des tableaux
+ int [ ] a [ 3 ] ;
+// a = null;
+ if ( a == null ) show ( "NULL" );
+
+ a [ 2 / 2 ] [ 2 ]= 5 ;
+ int [ ] b ; b = a [1] ;
+ b [ 0 ] = -4;
+ a [ 4 / 2 ] [ 1 ]= 1 ;
+ show ( a , b ) ;
+ return ;
+ {
+ toto chose = new toto (5 ) ;
+ toto truc = chose ;
+ show ( chose, chose.retval( 100 ) ,
+ truc, truc.retval (40 ) ) ;
+
+ return;
+ }
+ {
+ point A = new
+ point ( 4 * 4 , 2 ) ;
+ show ( A ) ;
+ return;
+ }
+ {
+ show ( T ( 1 ) , T ( 3.7 ) ) ;
+ return;
+ }
+
+ {
+ point A ( 3, 4 ) ,
+ B = A ;
+
+ int n = -4;
+ show ( n );
+
+ show ( A, B ) ;
+
+ boolean a = false;
+ boolean b = a or true;
+ if ( not a and b ) ;
+ return;
+ }
+ {
+ // test try
+ float x = nan ; int z = 0 ;
+ try {
+// throw ( 3 * 4 + 33 ) ;
+ int zz ; goto ( 12 ) ; z = 1 ; z = 0 / 0 ; z = 2 ;
+ }
+ catch ( 45 + 0 * 6000 )
+ {
+ show( "Exception 6000", z ) ;
+ }
+ catch ( x == 0 ) { show( "x nul" ) ; }
+ finally { show ( "fini" ) ; }
+ show ( "continue" );
+ return;
+ }
+ {
+ // test des if
+ int a = 3;
+ if ( a == 3 ) show ( "33");
+ else show ( "44");
+ if ( a != 3 ) show ( "333");
+ else show ( "444");
+ return;
+ }
+ {
+ int a = 0;
+ // test break
+un:
+ while ( true )
+ {
+deux:
+ while ( true )
+ {
+ a++;
+ if ( a == 2 ) continue;
+ if ( a == 3 ) break deux;
+ show ( a ) ;
+ if ( a == 5 ) break un;
+ }
+ show ( "DEUX" );
+ }
+ return;
+ }
+ {
+ // test switch
+ int a = 0;
+
+ switch ( a )
+ {
+ case 1 : show( "un" ) ; break;
+ case 2 : show( "deux" ) ; // break;
+ case 3 : show( "trois" ) ; break;
+ case 4 : show( "quatre" ) ; // break;
+ default : show( "par défaut" ) ;
+ }
+ return;
+ }
+ {
+ // test boucle while
+ float z = 3.3;
+ while ( z > 0 )
+ { show ( z-- ) ; }
+ return;
+ }
+
+ {
+ // test boucle do
+ float y = 3.3;
+ do { int x = 0; show(y); y++; } while ( y < 7 ) ;
+ return;
+ }
+ // test boucle for
+ int j = -7; show ( j );
+ for ( int ii = 3, j = 31; ii < 6 ; ++ii, j = j -3 )
+ {
+ j = 10 * j;
+ show ( ii, j );
+ }
+ return;
+{
+ // déclarations de variables
+ int a; int b = 3; int c = 4*b, d = 1, e;
+ float x; float y = 3.3; float z = y / 2, u = 1, v;
+ boolean t; boolean tt = true or false; boolean ttt = false, tttt = true, t5;
+ string s; string ss = "hello"; string s2 = ss + " plus", s3 = "s3", s4;
+
+ show( b, c, d );
+ show( y, z, u );
+ show( tt, ttt, tttt );
+ show( ss, s2, s3 );
+}
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/TestCB1.txt b/test/cbot/scenarios/TestCB1.txt
new file mode 100644
index 0000000..516db47
--- /dev/null
+++ b/test/cbot/scenarios/TestCB1.txt
@@ -0,0 +1,18 @@
+extern public void toto()
+{
+ print( "hello" ) ;
+ print( fac(5) );
+ print( t() ) ;
+}
+
+public int fac(int n)
+{
+ if ( n<2 ) return 1;
+ return n * fac(n-1);
+}
+
+point t()
+{
+ point a(1,2);
+ return a;
+}
diff --git a/test/cbot/scenarios/TestCBot1.txt b/test/cbot/scenarios/TestCBot1.txt
new file mode 100644
index 0000000..d27b4f8
--- /dev/null
+++ b/test/cbot/scenarios/TestCBot1.txt
@@ -0,0 +1,27 @@
+
+class CPoint2
+{
+ float x, y;
+ void CPoint2(float x, float y)
+ {
+ this.x = x;
+ this.y = y;
+ }
+}
+
+public extern void T ( )
+{
+ CPoint2 X( 12, 33 ), Y ( -4, 4/3 );
+ print ( X, Y ) ;
+}
+
+public extern void Hello ( )
+
+{
+ println ( "Hello" );
+}
+
+public extern void test ( int n )
+{
+ for ( int i = n; i>0 ; i--) print (i);
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/TestCBot3.txt b/test/cbot/scenarios/TestCBot3.txt
new file mode 100644
index 0000000..b915f96
--- /dev/null
+++ b/test/cbot/scenarios/TestCBot3.txt
@@ -0,0 +1,24 @@
+public extern void Test ()
+{
+ for ( int x = 100000; x>0 ; x-- ) { }
+}
+
+float MaRoutine( CPoint A, CPoint B )
+{
+ A.x -= B.x ; // distance en x
+ A.y -= B.y ; // distance en y
+ A.x *= A.x; // carré de la distance
+ A.y += A.y; // carré de la distance
+ println ( A, B ) ;
+ return ( A.x + A.y ) ;
+}
+
+public extern void TestAB ( )
+{
+ CPoint A(3, 5) ;
+ CPoint B(4, -2);
+ println ( A, B ) ;
+ MaRoutine( A, B ) ;
+ println ( A, B ) ;
+}
+
diff --git a/test/cbot/scenarios/TestNull.txt b/test/cbot/scenarios/TestNull.txt
new file mode 100644
index 0000000..f447245
--- /dev/null
+++ b/test/cbot/scenarios/TestNull.txt
@@ -0,0 +1,15 @@
+extern public void TestNull ()
+{
+ CPoint pointeur = null;
+
+ try {
+ pointeur.x = 4; }
+ catch ( 6007 ) {}
+
+ pointeur = new CPoint(1,2);
+
+ print ( pointeur.x, pointeur.y,
+ pointeur );
+
+ pointeur.x = 5;
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/TestRestoreState.txt b/test/cbot/scenarios/TestRestoreState.txt
new file mode 100644
index 0000000..1e49e37
--- /dev/null
+++ b/test/cbot/scenarios/TestRestoreState.txt
@@ -0,0 +1,67 @@
+// routine de Daniel qui plante après RestoreState
+
+extern void object::Attack( )
+{
+ int list[], i;
+ object p;
+ float dist, prox;
+ point nav1, nav2, dest;
+ boolean advance = true;
+
+ i = 0;
+ list[i++] = WingedGrabber;
+ list[i++] = TrackedGrabber;
+ list[i++] = WheeledGrabber;
+ list[i++] = LeggedGrabber;
+ list[i++] = WingedShooter;
+ list[i++] = TrackedShooter;
+ list[i++] = WheeledShooter;
+ list[i++] = LeggedShooter;
+ list[i++] = WingedOrgaShooter;
+ list[i++] = TrackedOrgaShooter;
+ list[i++] = WheeledOrgaShooter;
+ list[i++] = LeggedOrgaShooter;
+ list[i++] = WingedSniffer;
+ list[i++] = TrackedSniffer;
+ list[i++] = WheeledSniffer;
+ list[i++] = LeggedSniffer;
+ list[i++] = Thumper;
+ list[i++] = PhazerShooter;
+ list[i++] = Recycler;
+ list[i++] = Shielder;
+ list[i++] = Subber;
+ list[i++] = Me;
+
+ nav1.x = 1;//cmdline(0);
+ nav1.y = 1;//cmdline(1);
+ nav2.x = 2;//cmdline(2);
+ nav2.y = 2;//cmdline(3);
+
+ while ( true )
+ {
+ while ( true )
+ {
+ // ennemi à proximité ?
+ p = radar(list, 0, 360, 0, 40);
+ if ( p == null ) break;
+ // lui tire dessus
+ fire(p.position);
+ }
+
+ // se promène vers le point A
+ goto(nav1);
+
+ while ( true )
+ {
+ // ennemi à proximité ?
+ p = radar(list, 0, 360, 0, 40);
+ if ( p == null ) break;
+ // lui tire dessus
+ fire(p.position);
+ }
+
+ // se promène vers le point B
+ goto(nav2);
+ }
+}
+
diff --git a/test/cbot/scenarios/TestStatic.txt b/test/cbot/scenarios/TestStatic.txt
new file mode 100644
index 0000000..f501aa5
--- /dev/null
+++ b/test/cbot/scenarios/TestStatic.txt
@@ -0,0 +1,31 @@
+class ESSAI
+{
+ int x = 0;
+ static int nb = 3;
+ static int [ ] array ;
+
+ void Put( int val)
+ {
+show(nb);
+ array[ nb ] = val;
+// this.nb++;
+ this.nb = this.nb + 1;
+show(nb, array);
+ }
+ int Get( )
+ {
+ nb--;
+show("out", nb, array);
+ return array[ nb ] ;
+ }
+}
+
+extern public void T()
+{
+ ESSAI t1 ( ) ;
+ ESSAI t2 ( ) ;
+ t1.nb++;
+ t1.Put( 11 ); t1.Put( 12 ); t2.Put( 13 );
+
+ show ( t1.Get(), t2.Get(), t2.Get() ) ;
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/TestStr.txt b/test/cbot/scenarios/TestStr.txt
new file mode 100644
index 0000000..683ec1b
--- /dev/null
+++ b/test/cbot/scenarios/TestStr.txt
@@ -0,0 +1,17 @@
+extern public void TSTR()
+{
+ string s = "C'est un essai";
+
+ print ( s, strlen(s), strleft(s, 3), strright(s,3), strmid(s, 2), strmid(s,2,3), strfind(s, "un"), strfind(s, "sdgfld") );
+
+ show ( strupper(s), strlower(s) );
+
+ s = "123.45" ;
+ print ( strval(s) );
+
+
+ string sub = strright("abcdef", 2); // sub vaut "ef###", # étant un caractère bizarre quelconque
+ show (sub);
+ int pos = strfind("abcdef", "xy"); // pos vaut -1. Pourquoi pas nan ?
+ show(pos);
+}
diff --git a/test/cbot/scenarios/Z.txt b/test/cbot/scenarios/Z.txt
new file mode 100644
index 0000000..714119b
--- /dev/null
+++ b/test/cbot/scenarios/Z.txt
@@ -0,0 +1,14 @@
+public extern void tp()
+{
+ int a [4], b[];
+ a [ 0 ] = 8 ;
+
+ b = T ( a ) ;
+ show ( a, b );
+}
+
+int[] T ( int[] Z )
+{
+ for ( int i = 0; i < 4 ; i++ ) Z[ i ] = i * i ;
+ return Z;
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/a.txt b/test/cbot/scenarios/a.txt
new file mode 100644
index 0000000..6107342
--- /dev/null
+++ b/test/cbot/scenarios/a.txt
@@ -0,0 +1,312 @@
+object radarGuepe(point orig, float dist)
+{
+ int i;
+ object pr, r;
+ float mindist;
+
+ i = 0;
+ mindist = 1000;
+ while (i<30)
+ {
+ pr = radar(i);
+ if (pr != null)
+ {
+
+ if (F(orig, pr.position) < mindist and pr.category == AlienWasp and pr.altitude > 3)
+ {
+ mindist = distance(orig, pr.position);
+ r = pr;
+ }
+ }
+ i = i+1;
+ }
+ if (mindist < dist) return(r); else return(null);
+}
+
+
+class Guepe
+{
+
+ point pos;
+
+
+ void cherche(point orig, float dist)
+ {
+ object p;
+ point o;
+
+ p = radarGuepe(orig, dist);
+ while (p == null)
+ {
+ wait(0.1);
+ p = radarGuepe(orig, dist);
+ }
+
+ pos.x = p.position.x;
+ pos.y = p.position.y;
+ pos.z = p.position.z;
+
+ //o = p.position;
+ //wait(0.1);
+
+ //vitessex = (p.position.x - o.x)/0.1;
+ //vitessey = (p.position.y - o.y)/0.1;
+ //vitessez = (p.position.z - o.z)/0.1;
+
+ }
+
+
+ void tire(point orig, float orient)
+ {
+ //float t = 3; //temps d'anticipation
+ float angle;
+ point cible;
+
+ cible.x = pos.x;// + t*vitessex;
+ cible.y = pos.y;// + t*vitessey;
+ cible.z = pos.z;// + t*vitessez;
+
+ if (cible.x == 0) angle = 90; else
+ angle = atan(cible.y / cible.x);
+ if (cible.x < 0) angle = angle + 180;
+ angle = angle - orient;
+ if (angle > 180) angle = angle - 360;
+ if (angle < -180) angle = angle + 360;
+ turn(angle);
+
+ angle = atan((cible.z-orig.z) / distance2d(orig, cible));
+ aim(angle);
+
+ fire(0.1);
+
+ }
+}
+
+extern void object::Fourmi6()
+{
+ //fps(1000);
+ Guepe guepe = new Guepe();
+
+ while (true)
+ {
+ guepe.cherche(position, 50);
+
+ guepe.tire(position, orientation);
+ }
+}
+object radarGuepe(point orig, float dist)
+{
+ int i;
+ object pr, r;
+ float mindist;
+
+ i = 0;
+ mindist = 1000;
+ while (i<30)
+ {
+ pr = radar(i);
+ if (pr != null)
+ {
+
+ if (F(orig, pr.position) < mindist and pr.category == AlienWasp and pr.altitude > 3)
+ {
+ mindist = distance(orig, pr.position);
+ r = pr;
+ }
+ }
+ i = i+1;
+ }
+ if (mindist < dist) return(r); else return(null);
+}
+
+
+class Guepe
+{
+
+ point pos;
+
+
+ void cherche(point orig, float dist)
+ {
+ object p;
+ point o;
+
+ p = radarGuepe(orig, dist);
+ while (p == null)
+ {
+ wait(0.1);
+ p = radarGuepe(orig, dist);
+ }
+
+ pos.x = p.position.x;
+ pos.y = p.position.y;
+ pos.z = p.position.z;
+
+ //o = p.position;
+ //wait(0.1);
+
+ //vitessex = (p.position.x - o.x)/0.1;
+ //vitessey = (p.position.y - o.y)/0.1;
+ //vitessez = (p.position.z - o.z)/0.1;
+
+ }
+
+
+ void tire(point orig, float orient)
+ {
+ //float t = 3; //temps d'anticipation
+ float angle;
+ point cible;
+
+ cible.x = pos.x;// + t*vitessex;
+ cible.y = pos.y;// + t*vitessey;
+ cible.z = pos.z;// + t*vitessez;
+
+ if (cible.x == 0) angle = 90; else
+ angle = atan(cible.y / cible.x);
+ if (cible.x < 0) angle = angle + 180;
+ angle = angle - orient;
+ if (angle > 180) angle = angle - 360;
+ if (angle < -180) angle = angle + 360;
+ turn(angle);
+
+ angle = atan((cible.z-orig.z) / distance2d(orig, cible));
+ aim(angle);
+
+ fire(0.1);
+
+ }
+}
+
+extern void object::Fourmi6()
+{
+ //fps(1000);
+ Guepe guepe = new Guepe();
+
+ while (true)
+ {
+ guepe.cherche(position, 50);
+
+ guepe.tire(position, orientation);
+ }
+}
+object radarGuepe(point orig, float dist)
+{
+ int i;
+ object pr, r;
+ float mindist;
+
+ i = 0;
+ mindist = 1000;
+ while (i<30)
+ {
+ pr = radar(i);
+ if (pr != null)
+ {
+
+ if (F(orig, pr.position) < mindist and pr.category == AlienWasp and pr.altitude > 3)
+ {
+ mindist = distance(orig, pr.position);
+ r = pr;
+ }
+ }
+ i = i+1;
+ }
+ if (mindist < dist) return(r); else return(null);
+}
+
+
+class Guepe
+{
+
+ point pos;
+
+
+ void cherche(point orig, float dist)
+ {
+ object p;
+ point o;
+
+ p = radarGuepe(orig, dist);
+ while (p == null)
+ {
+ wait(0.1);
+ p = radarGuepe(orig, dist);
+ }
+
+ pos.x = p.position.x;
+ pos.y = p.position.y;
+ pos.z = p.position.z;
+
+ //o = p.position;
+ //wait(0.1);
+
+ //vitessex = (p.position.x - o.x)/0.1;
+ //vitessey = (p.position.y - o.y)/0.1;
+ //vitessez = (p.position.z - o.z)/0.1;
+
+ }
+
+
+ void tire(point orig, float orient)
+ {
+ //float t = 3; //temps d'anticipation
+ float angle;
+ point cible;
+
+ cible.x = pos.x;// + t*vitessex;
+ cible.y = pos.y;// + t*vitessey;
+ cible.z = pos.z;// + t*vitessez;
+
+ if (cible.x == 0) angle = 90; else
+ angle = atan(cible.y / cible.x);
+ if (cible.x < 0) angle = angle + 180;
+ angle = angle - orient;
+ if (angle > 180) angle = angle - 360;
+ if (angle < -180) angle = angle + 360;
+ turn(angle);
+
+ angle = atan((cible.z-orig.z) / distance2d(orig, cible));
+ aim(angle);
+
+ fire(0.1);
+
+ }
+}
+
+extern void object::Fourmi6()
+{
+ //fps(1000);
+ Guepe guepe = new Guepe();
+
+ while (true)
+ {
+ guepe.cherche(position, 50);
+
+ guepe.tire(position, orientation);
+ }
+}
+
+public extern void TestTableau ()
+{
+ int tableau [ 12 ] ;
+
+ point array[ 12 ] [ 14 ] ;
+
+ point zéro ( 1, 2 ) ;
+ point a = zéro ;
+
+ for ( int i = 0 ; i < 10 ; i++ ) array[ i ] [ i ]= zéro ;
+
+ array[ 5 ] [3 ] . x =1.5 ;
+
+ array[ 2 ] [ 2 ] . y = array[ 5 ] [ 5 ] . x ;
+
+ array[ 4 ] = array [ 2 ] ;
+
+ for ( int i = 0 ; i < 10 ; i++ ) for ( int j = 0 ; j < 4 ; j++ ) println ( i, j, array [ i ] [ j ] ) ;
+
+ show( zéro, a, array );
+
+}
+
diff --git a/test/cbot/scenarios/bug.txt b/test/cbot/scenarios/bug.txt
new file mode 100644
index 0000000..4ec6eb3
--- /dev/null
+++ b/test/cbot/scenarios/bug.txt
@@ -0,0 +1,12 @@
+public extern void object::Bug()
+{
+ point a;
+ a = position;
+ TEST();
+ float d=dist(a, position);
+}
+
+float dist(point a, point b)
+{
+ return a.x-b.x;
+}
diff --git a/test/cbot/scenarios/bugmw.txt b/test/cbot/scenarios/bugmw.txt
new file mode 100644
index 0000000..284ee43
--- /dev/null
+++ b/test/cbot/scenarios/bugmw.txt
@@ -0,0 +1,9 @@
+extern public void main()
+{
+ show(fact(30)) ;
+}
+
+public int fact(int n)
+{
+ return (fact(n-1)*n) ;
+}
diff --git a/test/cbot/scenarios/ccc.txt b/test/cbot/scenarios/ccc.txt
new file mode 100644
index 0000000..dbcd1d5
--- /dev/null
+++ b/test/cbot/scenarios/ccc.txt
@@ -0,0 +1,8 @@
+public extern void ccc()
+{
+ int a;
+ a = 0 ;
+
+ if ( a == 0 );
+
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/enum.txt b/test/cbot/scenarios/enum.txt
new file mode 100644
index 0000000..a592a7f
--- /dev/null
+++ b/test/cbot/scenarios/enum.txt
@@ -0,0 +1,9 @@
+
+enum JourDeLaSemaine {
+ lundi = 1,
+ mardi,
+ mercredi,
+ jeudi,
+ vendredi,
+ samedi,
+ dimanche = 0 } \ No newline at end of file
diff --git a/test/cbot/scenarios/fibo.txt b/test/cbot/scenarios/fibo.txt
new file mode 100644
index 0000000..88f5357
--- /dev/null
+++ b/test/cbot/scenarios/fibo.txt
@@ -0,0 +1,25 @@
+
+extern public int Fibo( int n, boolean b )
+{
+ if ( n < 2 ) return n;
+ int a = Fibo(n-1, b) + Fibo(n-2, false);
+ if ( b ) print (n + "=" + a);
+ return a;
+}
+
+extern public void t()
+{
+ Fibo( 23, true);
+}
+
+extern public void tt()
+{
+ t();
+}
+
+// cette routine n'est évidemment pas du tout obtimisée
+// c'est même un très mauvais exemple de programmation récursive
+
+// pour un test de durée, Fibo(23, true) prend
+// en mode Debug 67 secondes
+// en mode Release 8 secondes
diff --git a/test/cbot/scenarios/file.txt b/test/cbot/scenarios/file.txt
new file mode 100644
index 0000000..2a22dd9
--- /dev/null
+++ b/test/cbot/scenarios/file.txt
@@ -0,0 +1,70 @@
+class CLASS22
+{
+ static int nb = 2;
+ void T22 ( ) { nb = nb / 0 ; }
+}
+
+public extern void object :: TEST()
+{
+ switch ( 1 )
+ {
+ case 1:
+ {
+ file h();
+ h.open("Mon Fichier.txt", "r");
+show ( h.filename, h.handle );
+h.filename = "xx";
+h.handle = 1 ;
+ h.readln();
+ h.close();
+ }
+ case 2:
+ {
+ file h("Mon Fichier.txt");
+ h.open("r");
+ h.readln();
+ h.close();
+ }
+ case 3:
+ {
+ file h("Mon Fichier.txt", "r");
+ h.readln();
+ h.close();
+ }
+ case 4:
+ {
+ file h();
+ h.filename = "Mon Fichier.txt";
+ h.open("r");
+ h.readln();
+ h.close();
+ }
+ case 5:
+ {
+ file h = fileopen( "Mon 2Fichier.txt", "r" );
+ h.readln();
+ h.close();
+ }
+ }
+{
+ file h( ) ;
+ h.filename = "Test.h";
+ h.open ( "r" );
+
+
+ file pf ( "Mon Fichier.txt" ) ;
+ pf . open ( "w" ) ;
+ pf . writeln ( "Voici encore du texte" ) ;
+ pf . writeln ( "et une seconde ligne" ) ;
+ pf . close( );
+
+ pf . open ( "r" ) ;
+
+ while ( not pf . eof( ) )
+ {
+ string s = pf . readln ( );
+ show ( s );
+ }
+ pf.close( );
+}
+}
diff --git a/test/cbot/scenarios/h.txt b/test/cbot/scenarios/h.txt
new file mode 100644
index 0000000..c395319
--- /dev/null
+++ b/test/cbot/scenarios/h.txt
@@ -0,0 +1,5 @@
+void tf()
+{
+ file h;
+ h.handle += 1 ;
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/include.txt b/test/cbot/scenarios/include.txt
new file mode 100644
index 0000000..e8f8cc9
--- /dev/null
+++ b/test/cbot/scenarios/include.txt
@@ -0,0 +1,27 @@
+class Z
+{
+ static int x = 0;
+ private int y;
+
+ void T( )
+ {
+ // autorisé ici
+ y = x ;
+ this.y = this.x ;
+ x = y ;
+ this.x = this.y ;
+ }
+}
+
+extern public void test()
+{
+ Z a();
+ 3 * a.x; // autorisé
+//vu 3 * a.y; // interdit
+//vu a.y = 3; // interdit ici
+ a.x = 1; // autorisé
+
+ show ( a );
+ a.T();
+ show ( a );
+}
diff --git a/test/cbot/scenarios/intrinsic.txt b/test/cbot/scenarios/intrinsic.txt
new file mode 100644
index 0000000..f215791
--- /dev/null
+++ b/test/cbot/scenarios/intrinsic.txt
@@ -0,0 +1,16 @@
+public extern void TestIntrinsic()
+{
+ point a ( 1, 2 );
+ print (a);
+
+ a.x = 3;
+ a.y = 4;
+
+ point b = a;
+
+ println ( b.x, b.y, b ) ;
+ if ( b == a ) b.y = 0;
+ println (a,b);
+ if ( b != a ) b.y = a.y;
+ println(a,b);
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/methode1.txt b/test/cbot/scenarios/methode1.txt
new file mode 100644
index 0000000..080bba2
--- /dev/null
+++ b/test/cbot/scenarios/methode1.txt
@@ -0,0 +1,57 @@
+class t {
+ point p;
+}
+
+void object :: toto()
+{
+ show ( Position ) ;
+}
+
+extern public void object :: XX()
+{
+ int test [];
+ test [ 9999 ] = 3;
+
+ toto () ;
+/*
+ Radar();
+
+ object test ;
+ test = this. Radar();
+
+ do {
+ test = this.Radar();
+ } while ( test == null );
+
+/*
+ t test [ 4 ];
+ for ( int i = 0 ; i < 4 ; i++ ) test [ i ] = new t();
+ test [ 3 ] .p.x = 2;
+ show ( test );
+/*
+ int a = nan;
+ show ( a ) ;
+
+ a = TypeMarkPath;
+ show ( a, a++, --a ) ;
+
+ if ( a != nan ) a += 1 ;
+
+ a = TypeMarkPath;
+ float q = a ;
+ show ( a, q ) ;
+
+return;
+
+ a += ++a;
+ show ( a ) ;
+
+ boolean i = false;
+
+ if ( i == true ) {}
+
+ object p;
+ if ( p == null) { p = p ; }
+*/
+}
+
diff --git a/test/cbot/scenarios/methode2.txt b/test/cbot/scenarios/methode2.txt
new file mode 100644
index 0000000..76ce7f4
--- /dev/null
+++ b/test/cbot/scenarios/methode2.txt
@@ -0,0 +1,50 @@
+
+extern void Toto()
+{
+ TEST(12);
+
+ for ( int i = 0 ; i<1000; i++)
+ {
+ int j = 1;
+ if (i==55) TEST(12);
+ }
+
+ TEST(2);
+
+
+// Nouveau();
+ int toto[4];
+ point Z[3];
+
+ Z[1].x = 11; Z[1].y = 12;
+
+ toto[2] = 12;
+ toto[1] = nan;
+
+// point test, autre(2,3) ;
+// object titi = Radar();
+
+ TEST ( 1 ) ;
+
+ toto[0] = 11;
+
+ TEST ( 2 ) ;
+
+ toto[6] = 0;
+}
+
+extern void object::Nouveau()
+{
+ point a;
+ a = np(Position);
+}
+
+point np(point b)
+{
+ point c;
+ c.x = b.y;
+ c.y = b.x;
+ return c ;
+}
+
+
diff --git a/test/cbot/scenarios/mp1.txt b/test/cbot/scenarios/mp1.txt
new file mode 100644
index 0000000..599cfc4
--- /dev/null
+++ b/test/cbot/scenarios/mp1.txt
@@ -0,0 +1,25 @@
+class Guepet
+{
+
+ float a;
+ float b;
+
+ void init()
+ {
+ a = 12.34;
+ b = 56.78;
+ }
+
+
+}
+
+extern void object::Fourmi6()
+{
+ Guepet guepe =new Guepet();
+
+ guepe.init();
+
+
+ show("test "+guepe.a+" "+guepe.b);
+
+}
diff --git a/test/cbot/scenarios/mp2.txt b/test/cbot/scenarios/mp2.txt
new file mode 100644
index 0000000..1c2972c
--- /dev/null
+++ b/test/cbot/scenarios/mp2.txt
@@ -0,0 +1,28 @@
+class Guepet
+{
+
+ float a;
+ float b;
+
+ void init()
+ {
+ a = 12.34;
+ b = 56.78;
+
+ object x = radar(123);
+ show("radar "+x.position.x);
+ show("C'est fait");
+ }
+
+
+}
+
+extern void object::Fourmi6()
+{
+ Guepet guepe=new Guepet();
+
+ guepe.init();
+
+ show("test "+guepe.a+" "+guepe.b);
+
+}
diff --git a/test/cbot/scenarios/mw.txt b/test/cbot/scenarios/mw.txt
new file mode 100644
index 0000000..c237670
--- /dev/null
+++ b/test/cbot/scenarios/mw.txt
@@ -0,0 +1,16 @@
+extern public void main()
+{
+// goto( 3, 4 );
+
+ while( true )
+ {
+ try { goto (12) ; }
+ catch( FF( ) )
+ { show( "ko"); }
+ }
+}
+
+boolean FF()
+{
+ return false;
+}
diff --git a/test/cbot/scenarios/null.txt b/test/cbot/scenarios/null.txt
new file mode 100644
index 0000000..ae76b74
--- /dev/null
+++ b/test/cbot/scenarios/null.txt
@@ -0,0 +1,5 @@
+extern public void xxx ()
+{
+ CPoint test = null ;
+ if ( test == null ) show ( "NULL" );
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/opnew.txt b/test/cbot/scenarios/opnew.txt
new file mode 100644
index 0000000..7d6838c
--- /dev/null
+++ b/test/cbot/scenarios/opnew.txt
@@ -0,0 +1,20 @@
+extern public void xx ()
+{
+ CPoint pointeur, test = null ;
+ pointeur = new CPoint ( 3, 4 );
+
+ if ( test == null ) show ( "NULL" );
+
+ CPoint pp = pointeur;
+
+show( pointeur , pp );
+
+ pp.x = 33.3;
+ if ( pointeur.x != pp.x ) 0/0;
+
+ pp = new CPoint();
+// pointeur = pp;
+
+show( pointeur , pp );
+
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/plante.txt b/test/cbot/scenarios/plante.txt
new file mode 100644
index 0000000..363461b
--- /dev/null
+++ b/test/cbot/scenarios/plante.txt
@@ -0,0 +1,25 @@
+class Guepet
+{
+
+ point pos;
+ float t = 0.1;
+
+ void init()
+ {
+ pos.x = 12.123;
+ pos.y = 34.345;
+
+ F(t);
+ }
+
+
+}
+
+extern void object::Fourmi6()
+{
+ Guepet guepe=new Guepet();
+
+ guepe.init();
+
+ show ( guepe );
+}
diff --git a/test/cbot/scenarios/pointer.txt b/test/cbot/scenarios/pointer.txt
new file mode 100644
index 0000000..2d4d907
--- /dev/null
+++ b/test/cbot/scenarios/pointer.txt
@@ -0,0 +1,41 @@
+extern public void x ()
+{
+ show ( 3 ** 4 );
+ float z = 1e-3;
+ show ( z );
+
+ CPoint b ( 4,5 );
+ show ( b );
+
+ CPoint a ( ) ;
+ a.x = 21; a.y = 12;
+ show ( a ) ;
+
+ CPoint test = new CPoint ( 1,1 );
+ test = new CPoint ( 2, 2 );
+ show ( test );
+}
+
+// crée un objet et retourne son pointeur
+CPoint newcpoint()
+{
+ CPoint p = new CPoint ( 3, 3 );
+ return p;
+}
+
+extern public void y ()
+{
+ CPoint test = newcpoint();
+ println ( test );
+ dontmodif( test );
+ println ( test );
+}
+
+// ne doit pas modifier l'objet en paramètre
+void dontmodif ( CPoint pp )
+{
+ pp.x = 5;
+ pp.y = 2;
+ println ( pp, pp.x, pp.y );
+}
+
diff --git a/test/cbot/scenarios/postinc.txt b/test/cbot/scenarios/postinc.txt
new file mode 100644
index 0000000..cdf6ab5
--- /dev/null
+++ b/test/cbot/scenarios/postinc.txt
@@ -0,0 +1,7 @@
+extern public void X()
+{
+ point A [ ] ;
+ A[5] = new point (2,3);
+ int val = A[5].x++ + --A[5].y;
+ show ( A, val );
+}
diff --git a/test/cbot/scenarios/radar.txt b/test/cbot/scenarios/radar.txt
new file mode 100644
index 0000000..09d84a2
--- /dev/null
+++ b/test/cbot/scenarios/radar.txt
@@ -0,0 +1,39 @@
+extern void object::Bug( )
+{
+ try{ int a = 44 ; a = 12 / 0 ; }
+ catch(6000) { int b = 4 ; }
+ finally { int z = 1 ; }
+
+// tp ( A, B );
+
+/* int a = 4, b = 2, c = nan;
+ float x, y = 3/2, z = nan;
+ boolean i, j = false, k = true;
+
+ string s, ss = "xyz";
+
+ while ( false )
+ {
+ object left, right;
+
+ left = Radar(TypeMarkPath, -45, 120, 100);
+ right = Radar(TypeMarkPath, 45, 120, 100);
+
+ if ( left == null && right == null )
+ {
+ }
+ }
+ int t = fact ( 4 ) ;*/
+}
+
+void tp( point a , point b )
+{
+ a.x += b.x;
+}
+
+
+int fact( int n )
+{
+ if ( n < 2 ) return n;
+ return n * fact ( n - 1 ) ;
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/solution.txt b/test/cbot/scenarios/solution.txt
new file mode 100644
index 0000000..f78cf12
--- /dev/null
+++ b/test/cbot/scenarios/solution.txt
@@ -0,0 +1,13 @@
+extern void object::Solution( )
+{
+show ( "Solution " + Position );
+ Carré(15);
+ Carré(25);
+}
+
+void object::Carré(float côté)
+{
+show ( "Carré " + Position );
+ Move(côté);
+ Turn(-90);
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/test.txt b/test/cbot/scenarios/test.txt
new file mode 100644
index 0000000..0693994
--- /dev/null
+++ b/test/cbot/scenarios/test.txt
@@ -0,0 +1,8 @@
+extern public void x()
+{
+ float a= 1, b = 2;
+ a = b * ( 2 + 2 );
+ print (a);
+ a += 4;
+ print (a);
+}
diff --git a/test/cbot/scenarios/test23.txt b/test/cbot/scenarios/test23.txt
new file mode 100644
index 0000000..d6e1ddd
--- /dev/null
+++ b/test/cbot/scenarios/test23.txt
@@ -0,0 +1,10 @@
+extern public void object::TEST23()
+{
+ CLASS22 T;
+ T.T22( ) ;
+
+ show( position );
+ show( this.position );
+
+// T22();
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/testmw.txt b/test/cbot/scenarios/testmw.txt
new file mode 100644
index 0000000..6570f6d
--- /dev/null
+++ b/test/cbot/scenarios/testmw.txt
@@ -0,0 +1,14 @@
+extern public int testmw( int a)
+{
+ boolean b = true ;
+
+ if (b)
+ return 1 ;
+ else
+ return a ; 0 * testmw(a-1) ;
+}
+
+public int Fibo2 ( int n )
+{
+ print ( " bof " );
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/this.txt b/test/cbot/scenarios/this.txt
new file mode 100644
index 0000000..b8a9e04
--- /dev/null
+++ b/test/cbot/scenarios/this.txt
@@ -0,0 +1,13 @@
+extern void object :: TEST22 ( )
+{
+ show( position );
+ show( this.position );
+
+ T();
+}
+
+public void object :: T22()
+{
+ show( position );
+ show( this.position );
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/tt.txt b/test/cbot/scenarios/tt.txt
new file mode 100644
index 0000000..cd13c9d
--- /dev/null
+++ b/test/cbot/scenarios/tt.txt
@@ -0,0 +1,12 @@
+extern public void T() { T1(); }
+
+public void T1()
+{
+ show( "T1" );
+ T2();
+}
+
+public void T2()
+{
+ show( "T2" );
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/tt2.txt b/test/cbot/scenarios/tt2.txt
new file mode 100644
index 0000000..ad9dc1d
--- /dev/null
+++ b/test/cbot/scenarios/tt2.txt
@@ -0,0 +1,5 @@
+extern public void TT()
+{
+ T1();
+ T2();
+} \ No newline at end of file
diff --git a/test/cbot/scenarios/vide.txt b/test/cbot/scenarios/vide.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/cbot/scenarios/vide.txt
diff --git a/test/cbot/scenarios/zz.txt b/test/cbot/scenarios/zz.txt
new file mode 100644
index 0000000..da764ac
--- /dev/null
+++ b/test/cbot/scenarios/zz.txt
@@ -0,0 +1,6 @@
+extern public void zz()
+{
+ MaClass TOTO ();
+
+ show (TOTO);
+} \ No newline at end of file