[ScryMUD] SVN Commit Info r746 - trunk/mud/grrmud/server
scrymud at wanfear.com
scrymud at wanfear.com
Sat Dec 11 00:36:24 PST 2004
Author: gingon
Date: 2004-12-11 00:36:23 -0800 (Sat, 11 Dec 2004)
New Revision: 746
Modified:
trunk/mud/grrmud/server/misc2.cc
trunk/mud/grrmud/server/misc2.h
Log:
added a simple distributed probability matrix class,
only supports single dimension probabilities.
Modified: trunk/mud/grrmud/server/misc2.cc
===================================================================
--- trunk/mud/grrmud/server/misc2.cc 2004-12-11 02:54:37 UTC (rev 745)
+++ trunk/mud/grrmud/server/misc2.cc 2004-12-11 08:36:23 UTC (rev 746)
@@ -2181,3 +2181,35 @@
return rm;
}
+
+
+
+void DistProbMatrix::add(int value, unsigned int weight){
+ int* tmp = NULL;
+ unsigned int tmp_size = 0;
+ unsigned int i = 0;
+
+ tmp_size = weight + size;
+ tmp = new int[tmp_size];
+
+ if(size != 0){
+ while(i < size){
+ tmp[i] = matrix[i];
+ ++i;
+ }
+ delete matrix;
+ }
+
+ while(i < tmp_size){
+ tmp[i] = value;
+ ++i;
+ }
+
+ matrix = tmp;
+ size = tmp_size;
+}
+
+int DistProbMatrix::get(){
+ return matrix[(rand() % size)-1];
+}
+
Modified: trunk/mud/grrmud/server/misc2.h
===================================================================
--- trunk/mud/grrmud/server/misc2.h 2004-12-11 02:54:37 UTC (rev 745)
+++ trunk/mud/grrmud/server/misc2.h 2004-12-11 08:36:23 UTC (rev 746)
@@ -174,4 +174,21 @@
door* get_target_door(int i_th, const String* target, critter& pc);
room* get_target_room(critter& pc);
+//distributed probability matrix code
+//only handles single dimension probability matrices
+//multidimension would be nice though...
+class DistProbMatrix {
+private:
+ int* matrix; //stores pointer to probability matrix
+ unsigned int size; // can only support MAX_INT entries
+public:
+ void add(int size, unsigned int weight);
+ int get();
+
+ DistProbMatrix(){size = 0;matrix = NULL;}
+ ~DistProbMatrix(){delete matrix;}
+};
+
+
+
#endif
More information about the ScryMUD
mailing list