[gbrainy] Dice problability logic game



commit ff75d0cff3a9016123a79ea921808972714e409b
Author: Jordi Mas <jmas softcatala org>
Date:   Sat Jan 16 13:55:35 2010 +0100

    Dice problability logic game

 data/game-graphics/dice.svg          |   70 ++++++++++++++++
 po/POTFILES.in                       |    1 +
 src/Clients/Classical/Builder/README |    3 +
 src/Games/GameList.cs                |    3 +-
 src/Games/Logic/PuzzleDice.cs        |  149 ++++++++++++++++++++++++++++++++++
 src/Games/Makefile.am                |    6 +-
 6 files changed, 229 insertions(+), 3 deletions(-)
---
diff --git a/data/game-graphics/dice.svg b/data/game-graphics/dice.svg
new file mode 100644
index 0000000..10e8feb
--- /dev/null
+++ b/data/game-graphics/dice.svg
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
+"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd";>
+<!-- Created with Sodipodi ("http://www.sodipodi.com/";) -->
+<svg height="800pt" id="svg548" inkscape:version="0.38.1" sodipodi:docbase="/var/www/html/svg_gallery/svg/toys" sodipodi:docname="dice.svg" 
+sodipodi:version="0.32" width="400pt" xmlns="http://www.w3.org/2000/svg"; xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"; 
+xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"; xmlns:xlink="http://www.w3.org/1999/xlink";>
+  <metadata>
+    <rdf:RDF xmlns:cc="http://web.resource.org/cc/"; xmlns:dc="http://purl.org/dc/elements/1.1/"; xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";>
+      <cc:Work rdf:about="">
+        <dc:title>Clipart by Nicu Buculei - piggybank</dc:title>
+        <dc:description></dc:description>
+        <dc:subject>
+          <rdf:Bag>
+            <rdf:li></rdf:li>
+            <rdf:li>game</rdf:li>
+            <rdf:li>recreation</rdf:li>
+          </rdf:Bag>
+        </dc:subject>
+        <dc:publisher>
+          <cc:Agent rdf:about="http://www.openclipart.org";>
+            <dc:title>Nicu Buculei</dc:title>
+          </cc:Agent>
+        </dc:publisher>
+        <dc:creator>
+          <cc:Agent>
+            <dc:title>Nicu Buculei</dc:title>
+          </cc:Agent>
+        </dc:creator>
+        <dc:rights>
+          <cc:Agent>
+            <dc:title>Nicu Buculei</dc:title>
+          </cc:Agent>
+        </dc:rights>
+        <dc:date></dc:date>
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
+        <cc:license rdf:resource="http://web.resource.org/cc/PublicDomain"/>
+        <dc:language>en</dc:language>
+      </cc:Work>
+      <cc:License rdf:about="http://web.resource.org/cc/PublicDomain";>
+        <cc:permits rdf:resource="http://web.resource.org/cc/Reproduction"/>
+        <cc:permits rdf:resource="http://web.resource.org/cc/Distribution"/>
+        <cc:permits rdf:resource="http://web.resource.org/cc/DerivativeWorks"/>
+      </cc:License>
+    </rdf:RDF>
+  </metadata>
+  <defs id="defs550"/>
+  <sodipodi:namedview id="base" inkscape:cx="200.00000" inkscape:cy="179.21011" inkscape:window-height="400" inkscape:window-width="400" inkscape:window-x="0" inkscape:window-y="0" inkscape:zoom="0" showgrid="true" showguides="true" snaptoguides="true"/>
+  <g id="g894">
+    <path d="M 84.7922 148.96 C 85.6401 148.96 324.754 254.103 324.754 254.103 L 485.012 111.652 L 268.791 53.1451 L 84.7922 148.96 z " id="path554" sodipodi:nodetypes="ccccc" style="fill:#e6e6e6;fill-rule:evenodd;stroke:#000000;stroke-width:9.4511288;stroke-linejoin:round;stroke-dasharray:none;" transform="matrix(1.000000,0.000000,0.000000,1.119522,-36.46066,-46.20438)"/>
+    <path d="M 49.17954 121.5090 C 49.17954 122.4583 50.87534 352.1809 50.02744 351.2315 L 289.9893 488.8756 L 286.5973 237.3202 L 49.17954 121.5090 z " id="path555" sodipodi:nodetypes="ccccc" style="font-size:12.000000;fill:#e6e6e6;fill-rule:evenodd;stroke:#000000;stroke-width:10.000000;stroke-linejoin:round;stroke-dasharray:none;"/>
+    <path d="M 326.45 478.802 L 323.906 254.103 L 485.012 111.652 L 482.468 328.72 L 326.45 478.802 z " id="path557" style="font-size:12.000000;fill:#e6e6e6;fill-rule:evenodd;stroke:#000000;stroke-width:9.4511288;stroke-linejoin:round;stroke-dasharray:none;" transform="matrix(1.000000,0.000000,0.000000,1.119522,-36.46066,-46.20438)"/>
+    <path d="M 262.6583 41.93024 C 250.7912 35.60112 216.7722 53.79735 239.7153 65.66441 C 257.1204 71.20240 284.0191 49.84166 262.6583 41.93024 z " id="path578" sodipodi:nodetypes="ccc" style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0000000pt;"/>
+    <path d="M 211.2342 72.78470 C 199.3671 66.45558 165.3481 84.65181 188.2912 96.51887 C 205.6963 102.0569 232.5950 80.69612 211.2342 72.78470 z " id="path580" sodipodi:nodetypes="ccc" style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0000000pt;"/>
+    <path d="M 151.8988 110.7593 C 140.0317 104.4302 106.0127 122.6264 128.9558 134.4935 C 146.3609 140.0315 173.2596 118.6707 151.8988 110.7593 z " id="path581" sodipodi:nodetypes="ccc" style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0000000pt;"/>
+    <path d="M 374.2090 83.06950 C 362.3419 76.74038 328.3229 94.93661 351.2660 106.8037 C 368.6711 112.3417 395.5698 90.98092 374.2090 83.06950 z " id="path586" sodipodi:nodetypes="ccc" style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0000000pt;"/>
+    <path d="M 327.5318 115.5063 C 315.6647 109.1771 281.6457 127.3734 304.5888 139.2404 C 321.9939 144.7785 348.8926 123.4177 327.5318 115.5063 z " id="path587" sodipodi:nodetypes="ccc" style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0000000pt;"/>
+    <path d="M 269.7786 155.8543 C 257.9115 149.5252 223.8925 167.7214 246.8356 179.5885 C 264.2407 185.1265 291.1394 163.7657 269.7786 155.8543 z " id="path588" sodipodi:nodetypes="ccc" style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0000000pt;"/>
+    <path d="M 98.89249 188.2911 C 87.02535 181.9619 77.53168 219.1455 100.4748 231.0125 C 117.8798 236.5505 120.2532 196.2024 98.89249 188.2911 z " id="path589" sodipodi:nodetypes="ccc" style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0000000pt;"/>
+    <path d="M 92.56337 288.7658 C 80.69623 282.4366 71.20256 319.6202 94.14568 331.4872 C 111.5507 337.0252 113.9241 296.6771 92.56337 288.7658 z " id="path590" sodipodi:nodetypes="ccc" style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0000000pt;"/>
+    <path d="M 229.4305 253.9557 C 217.5634 247.6265 208.0697 284.8101 231.0128 296.6771 C 248.4178 302.2151 250.7912 261.8670 229.4305 253.9557 z " id="path599" sodipodi:nodetypes="ccc" style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0000000pt;"/>
+    <path d="M 223.1014 354.4304 C 211.2343 348.1012 201.7406 385.2848 224.6837 397.1518 C 242.0887 402.6898 244.4621 362.3417 223.1014 354.4304 z " id="path600" sodipodi:nodetypes="ccc" style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0000000pt;"/>
+    <path d="M 329.9052 242.8797 C 316.4558 253.9556 322.7850 299.0506 338.6078 286.3922 C 356.8039 268.9872 347.3102 227.8480 329.9052 242.8797 z " id="path601" sodipodi:nodetypes="ccc" style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0000000pt;"/>
+    <path d="M 408.2280 275.3165 C 394.7786 286.3924 401.1078 331.4874 416.9306 318.8290 C 435.1267 301.4240 425.6330 260.2848 408.2280 275.3165 z " id="path602" sodipodi:nodetypes="ccc" style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0000000pt;"/>
+    <path d="M 178.7976 53.79734 C 159.8102 63.29098 75.15826 102.0568 64.08231 121.0442 C 73.57597 132.9112 184.3356 178.7974 183.5443 178.7974 C 182.7533 178.7974 42.72156 122.6265 178.7976 53.79734 z " id="path603" sodipodi:nodetypes="cccc" style="fill:#ffffff;fill-rule:evenodd;stroke-width:1.0000000pt;"/>
+    <path d="M 380.5380 61.70868 C 389.2406 64.87324 436.7089 75.15804 439.0825 80.69603 C 437.5002 87.02515 394.7787 124.9999 387.6584 130.5379 C 395.5698 120.2531 434.3355 83.06942 380.5380 61.70868 z " id="path604" sodipodi:nodetypes="cccc" style="fill-opacity:0.24999996;fill-rule:evenodd;stroke-width:1.0000000pt;"/>
+    <path d="M 395.5698 136.8670 C 400.3166 131.3290 440.6648 89.39857 443.8293 89.39857 C 446.2027 93.35426 444.6204 143.9873 443.8293 151.1075 C 439.8736 146.3607 453.3229 75.94921 395.5698 136.8670 z " id="path605" sodipodi:nodetypes="cccc" style="fill-opacity:0.24709995;fill-rule:evenodd;stroke-width:1.0000000pt;"/>
+  </g>
+</svg>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1180b12..19e0193 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -39,6 +39,7 @@ src/Games/Logic/PuzzleCounting.cs
 src/Games/Logic/PuzzleCountSeries.cs
 src/Games/Logic/PuzzleCoverPercentage.cs
 src/Games/Logic/PuzzleCube.cs
+src/Games/Logic/PuzzleDice.cs
 src/Games/Logic/PuzzleDivideCircle.cs
 src/Games/Logic/PuzzleEquation.cs
 src/Games/Logic/PuzzleExtraCircle.cs
diff --git a/src/Clients/Classical/Builder/README b/src/Clients/Classical/Builder/README
new file mode 100644
index 0000000..74c55e6
--- /dev/null
+++ b/src/Clients/Classical/Builder/README
@@ -0,0 +1,3 @@
+This has been generated by gtk-sharp-beans
+
+To be removed when gtk-sharp has been support for Builder 
diff --git a/src/Games/GameList.cs b/src/Games/GameList.cs
index 623e097..3d98cb4 100644
--- a/src/Games/GameList.cs
+++ b/src/Games/GameList.cs
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2009 Jordi Mas i Hernàndez <jmas softcatala org>
+ * Copyright (C) 2007-2010 Jordi Mas i Hernàndez <jmas softcatala org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -75,6 +75,7 @@ namespace gbrainy.Games
 			typeof (PuzzleTimeNow),
 			typeof (Puzzle3DCube),
 			typeof (PuzzlePredicateLogic),
+			typeof (PuzzleDice),
 		};
 
 		static Type[] CalculationTrainersInternal = new Type[] 
diff --git a/src/Games/Logic/PuzzleDice.cs b/src/Games/Logic/PuzzleDice.cs
new file mode 100644
index 0000000..56cbd2a
--- /dev/null
+++ b/src/Games/Logic/PuzzleDice.cs
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2010 Jordi Mas i Hernàndez <jmas softcatala org>
+ *
+ * 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 2 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+using Cairo;
+using Mono.Unix;
+using System;
+
+using gbrainy.Core.Main;
+using gbrainy.Core.Libraries;
+
+namespace gbrainy.Games.Logic
+{
+	public class PuzzleDice : Game
+	{
+		int problem;
+		const string format_string = "{0:##0.###}";
+
+		internal struct Problem
+		{
+			internal string question;
+			internal string answer;
+			internal string rationale;
+			internal bool single;
+
+			internal Problem (string question, string answer, string rationale, bool single)
+			{
+				this.question = question;
+				this.rationale = rationale;
+				this.answer = answer;
+				this.single = single;
+			}
+		};
+
+		Problem [] problems =
+		{
+			new Problem (Catalog.GetString ("What is the probability of getting a '2' or a '6' in a single throw of a fair 6 sided die? Answer using a fraction (e.g.: 1/2)."),
+				"1/3",
+				Catalog.GetString ("There are 2 of 6 possibilities."), true),
+
+			new Problem (Catalog.GetString ("What is the probability of not getting a '5' in a single throw of a fair 6 sided die? Answer using a fraction (e.g.: 1/2)."),
+				"5/6",
+				Catalog.GetString ("There are 5 of 6 possibilities."), true),
+
+			new Problem (Catalog.GetString ("Two fair 6 sided dices are thrown simultaneously. What is the probability of getting two even numbers?  Answer using a fraction (e.g.: 1/2)."),
+				"9/36",
+				Catalog.GetString ("There are 9 of 36 possibilities of getting an event number."), false),
+
+			new Problem (Catalog.GetString ("Two fair 6 sided dices are thrown simultaneously. What is the probability of getting two '6'?  Answer using a fraction (e.g.: 1/2)."),
+				"6/36",
+				Catalog.GetString ("There are 1 of 6 possibilities of getting first die and the same for the second die."), false),
+		};
+
+		public override string Name {
+			get {return Catalog.GetString ("Dice");}
+		}
+
+		public override string Question {
+			get { return problems[problem].question;}
+		}
+
+		public override string Answer {
+			get { return base.Answer + " " + problems[problem].rationale; }
+		}
+
+		public override void Initialize ()
+		{
+			problem = random.Next (problems.Length);
+			right_answer = problems[problem].answer;
+		}
+
+		public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
+		{
+			base.Draw (gr, area_width, area_height, rtl);
+			
+			if (problems[problem].single)
+				gr.DrawImageFromAssembly ("dice.svg", 0.3, 0.3, 0.4, 0.8);
+			else {
+				gr.DrawImageFromAssembly ("dice.svg", 0.1, 0.3, 0.4, 0.8);
+				gr.DrawImageFromAssembly ("dice.svg", 0.5, 0.3, 0.4, 0.8);
+			}
+		}
+
+		public override bool CheckAnswer (string answer)
+		{
+			string ans;
+			
+			ans = String.Format (format_string, FractionOrNumberToDouble (problems[problem].answer));
+			return ans.Equals (String.Format (format_string, FractionOrNumberToDouble (answer)));
+		}
+
+		// Takes a string with Fraction or Number and converts it to double
+		double FractionOrNumberToDouble (string answer)
+		{
+			string num_a = string.Empty;
+			string num_b = string.Empty;
+			double a, b;
+			double rslt;
+			bool first = true;		
+
+			for (int c = 0; c < answer.Length; c++)
+			{
+				if (answer[c] < '0' || answer[c] > '9') {
+					if (answer[c] != '-' && answer[c] != '.' && answer[c] != ',') {
+						first = false;
+						continue;
+					}
+				}
+			
+				if (first == true)
+					num_a += answer[c];
+				else
+					num_b += answer[c];
+			}
+
+			try {
+
+				if (num_b != string.Empty) {
+					a = Double.Parse (num_a);
+					b = Double.Parse (num_b);
+					rslt = (double) a / (double) b;
+				} else {
+					rslt = Double.Parse (num_a);
+				}
+
+			}
+
+			catch (FormatException) {
+				return 0;
+			}
+			return rslt;
+		}
+	}
+}
diff --git a/src/Games/Makefile.am b/src/Games/Makefile.am
index 1bffb12..abc0303 100644
--- a/src/Games/Makefile.am
+++ b/src/Games/Makefile.am
@@ -15,6 +15,7 @@ CSFILES =  \
 		Logic/PuzzleCountSeries.cs			\
 		Logic/PuzzleCoverPercentage.cs			\
 		Logic/PuzzleCube.cs				\
+		Logic/PuzzleDice.cs				\
 		Logic/PuzzleDivideCircle.cs			\
 		Logic/PuzzleEquation.cs				\
 		Logic/PuzzleExtraCircle.cs			\
@@ -70,8 +71,9 @@ CSFILES =  \
 		Calculation/CalculationTwoNumbers.cs
 
 RES = \
-$(top_srcdir)/data/game-graphics/present.svg  \
-$(top_srcdir)/data/game-graphics/handshake.svg
+$(top_srcdir)/data/game-graphics/present.svg  	\
+$(top_srcdir)/data/game-graphics/handshake.svg	\
+$(top_srcdir)/data/game-graphics/dice.svg
 
 REFS =  \
 	-r:System \



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]