/* Copyright (C) 2007 Andre Seidelt, All Rights Reserved. This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* * calculate and display statistics about the cells */ class Statistics { // number of mutations private int mMutations; // builder used for string creation private StringBuilder mSb; // number of happened ticks (this is != number of rendered frames) private int mTicks; // number of seconds the simulation was running (avg) private float mSeconds; // .ctor() public Statistics() { mSb = new StringBuilder(); mMutations = 0; mTicks = 0; mSeconds = 0; } // add a tick and inc seconds public void tick() { mTicks++; mSeconds += 1.0/frameRate; } // display statistics at the bottom of the screen public void paint() { fill(0, 255, 255); // line 1: counters mSb.setLength(0); mSb.append("Ticks: ").append(nf(mTicks, 6)).append(" (").append(nf((int) mSeconds, 5)).append(" sec)"); mSb.append(" - Number: ").append(nf(sCells.size(), 3)); mSb.append(" - Generation: ").append(nf(sGeneration, 5)); mSb.append(" - Mutations: ").append(nf(mMutations, 5)); text(mSb.toString(), 5, HEIGHT - 2*(FONT_SIZE+5)); // line 2: average values mSb.setLength(0); mSb.append("Ticks/Generation: "); if(sGeneration > 0) { mSb.append(nf(mTicks/sGeneration, 3)); } else { mSb.append(" "); } mSb.append(" - Ticks/Mutations: "); if(mMutations > 0) { mSb.append(nf(mTicks/mMutations, 3)); } else { mSb.append(" "); } mSb.append(" - Mutations/Generation: "); if(sGeneration > 0) { mSb.append(nf(float(mMutations)/float(sGeneration), 1, 5)); } mSb.append(" - Food/Cell: "); if(sCells.size() > 0) { mSb.append(nf(FOOD_AMMOUNT/sCells.size(), 5)); } text(mSb.toString(), 5, HEIGHT - (FONT_SIZE+5)); } }