Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
This simulation shows pure paper-rock-scissors players competing on a
two-dimensional grid (a donut-shaped world). Each time step, a random pixel is
chosen (that is, either a paper, rock or scissors player) and a random
neighbor. If one beats the other, the winner's strategy replaces the loser's
pixel.
Technical facts
./ToolPaperRockScissorsVcl/ProjectPrs.cpp
./ToolPaperRockScissorsVcl/UnitFormAbout.h
./ToolPaperRockScissorsVcl/UnitFormAbout.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "UnitFormAbout.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormAbout *FormAbout;
//---------------------------------------------------------------------------
__fastcall TFormAbout::TFormAbout(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
|
./ToolPaperRockScissorsVcl/UnitFormChart.h
./ToolPaperRockScissorsVcl/UnitFormChart.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "UnitFormChart.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormChart *FormChart;
//---------------------------------------------------------------------------
__fastcall TFormChart::TFormChart(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void TFormChart::Add(const double p, const double r, const double s)
{
Chart1->Series[0]->Add(p);
Chart1->Series[1]->Add(r);
Chart1->Series[2]->Add(s);
}
//---------------------------------------------------------------------------
void TFormChart::Clear()
{
Chart1->Series[0]->Clear();
Chart1->Series[1]->Clear();
Chart1->Series[2]->Clear();
}
//---------------------------------------------------------------------------
|
./ToolPaperRockScissorsVcl/UnitFormPrs.h
//---------------------------------------------------------------------------
#ifndef UnitFormPrsH
#define UnitFormPrsH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
#include <vector>
#include <memory>
enum EnumPrs { paper, rock, scissors };
class TFormChart;
//---------------------------------------------------------------------------
class TFormPrs : public TForm
{
__published: // IDE-managed Components
TPanel *PanelMenu;
TButton *ButtonPlayPause;
TButton *ButtonReset;
TEdit *EditWidth;
TEdit *EditHeight;
TLabel *LabelWidth;
TLabel *LabelHeight;
TButton *ButtonAbout;
TImage *ImageArea;
TTimer *Timer1;
TCheckBox *CheckBoxShow;
void __fastcall EditChange(TObject *Sender);
void __fastcall ButtonResetClick(TObject *Sender);
void __fastcall ButtonPlayPauseClick(TObject *Sender);
void __fastcall Timer1Timer(TObject *Sender);
void __fastcall ButtonAboutClick(TObject *Sender);
void __fastcall CheckBoxShowClick(TObject *Sender);
private: // User declarations
std::vector<std::vector<EnumPrs> > mV;
void DrawInitialArea();
void DrawArea();
void CountPopulation() const;
std::auto_ptr<TFormChart> mFormChart;
public: // User declarations
__fastcall TFormPrs(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormPrs *FormPrs;
//---------------------------------------------------------------------------
#endif
|
./ToolPaperRockScissorsVcl/UnitFormPrs.cpp
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.

This page has been created by the tool CodeToHtml