- Joined
- Jun 22, 2014
- Messages
- 11
- Reaction score
- 7
- First Language
- English
- Primarily Uses
Paramecium Core
One of the first things I wrote in ruby; because Math.
Graphs
A Self-explanatory Little Script
(Not part of Paramecium Core but requires it)
Upcoming Features
Ability System
Initial Release: 3/14/2015
Unused Features Excluded From Official Release
Vectors and Matrices
# A vector class, unused and unfinished.class Vector def intialize(v) @vector = v end def length() return @vector.length() end def to_a() return @vector end def component(i) return @vector[i+1] end def *(u) case (u) when Numeric w = Array.new @vector.each {|x| w.concat([x * c])} return Vector.new(w) when Vector if u.length() == self.length() w = u.to_a() i = 0 x = 0 for i in 0..(u.length() - 1) x += w * @vector end return x else return 0 end else return 0 end end def +(u) #i.e. u + v if u.length == self.length v = self.to_a() u_a = u.to_a() w = Array.new() i = 0 for i in 0..(v.length - 1) w = v + u_a end return Vector.new(w) else return nil end end def -(u) #i.e. u + v if u.length == self.length v = self.to_a() u_a = u.to_a() w = Array.new() i = 0 for i in 0..(v.length - 1) w = v - u_a end return Vector.new(w) else return nil end end def magnitude x = Math.sqrt(self * self) return x end def angle(u) if u.length == self.length x = u * self y = u.magnitude()*v.magnitude() if y != 0 z = x / y return Math.acos(z) end else return nil end end def st_basis(dim,n) if n <= dim i = 0 a = Array.new(dim) for i in 0..dim if i == n a = 1 else a = 0 end end return Vector.new(a) else return nil end end def distance(u) x = self - u d = x.magnitude return d end def angle_toUnitVector(θ) return Vector.new([Math.cos(θ),Math.sin(θ)]) end alias angle_toUV angle_toUnitVectorend# A matrix class, unfinished and unused.class Matrix def initialize(mx) #@initialized = true @n_rows = mx[0].length @n_columns = mx.length @matrix = mx end def dimensions return [@n_rows,@n_columns] end def rows return @n_rows end def columns return @n_columns end def entry(i,j) return @matrix[i-1][j-1] end def row(i) return @matrix[i-1] end def column(j) c = Array.new(@n_rows) i = 0 for i in 0..(@n_rows-1) c = @matrix[j-1] end return c end def self.scale(c) for i in 0..(@n_rows-1) for j in 0..(@n_columns-1) self[j] *= c end end end def trace if @n_columns == @n_rows x = 0 for i in 0..(@n_columns-1) x += @matrix end return x end end def minor(x,y) if (x <= @n_rows) && (y <= @n_columns) x -= 1 y -= 1 mat = @matrix mat.delete_at(y) l = @n_columns - 1 i = 0 for i in 0..(l) mat.delete_at(x) end return Matrix.new(mat) end end def determinant if @n_columns == @n_rows if @n_columns == 1 det = @matrix[0][0] elsif @n_columns == 2 det = @matrix[1][1]*@matrix[2][2] - @matrix[1][2]*@matrix[2][1] elsif @n_columns == 3 dm1 = self.entry(2,2)*self.entry(3,3) - self.entry(2,3)*self.entry(3,2) dm2 = self.entry(2,1)*self.entry(3,3) - self.entry(2,3)*self.entry(3,1) dm3 = self.entry(2,1)*self.entry(3,2) - self.entry(2,2)*self.entry(3,1) det = self.entry(1,1)*dm1 - self.entry(1,2)*dm2 +self.entry(1,3)*dm3 end end return det end def singular? if @n_columns == @n_rows if self.det == 0 return true else return false end end end def transform(vector) if self.columns == vector.length() v = Array.new(matrix.rows) i = 0 for i in 0..(matrix.rows-1) r = Vector.new(self.row(i+1)) v = vector * r end return v else return nil end end #def mult(m) #Right multiply # if @n_columns == m.rows # b = Array.new(@n_rows,0) # i = 0 # for i in 0..(@n_rows-1) # b = Array.new(m.columns,0) # end # i = 0 # for i in 0..(@n_rows-1) # j = 0 # for j in 0..(m.columns) # b[j] = Paramecium.dot_product(@matrix,m.column(j) # end # end # return Matrix.new( # endend
Vectors and Matrices
# A vector class, unused and unfinished.class Vector def intialize(v) @vector = v end def length() return @vector.length() end def to_a() return @vector end def component(i) return @vector[i+1] end def *(u) case (u) when Numeric w = Array.new @vector.each {|x| w.concat([x * c])} return Vector.new(w) when Vector if u.length() == self.length() w = u.to_a() i = 0 x = 0 for i in 0..(u.length() - 1) x += w * @vector end return x else return 0 end else return 0 end end def +(u) #i.e. u + v if u.length == self.length v = self.to_a() u_a = u.to_a() w = Array.new() i = 0 for i in 0..(v.length - 1) w = v + u_a end return Vector.new(w) else return nil end end def -(u) #i.e. u + v if u.length == self.length v = self.to_a() u_a = u.to_a() w = Array.new() i = 0 for i in 0..(v.length - 1) w = v - u_a end return Vector.new(w) else return nil end end def magnitude x = Math.sqrt(self * self) return x end def angle(u) if u.length == self.length x = u * self y = u.magnitude()*v.magnitude() if y != 0 z = x / y return Math.acos(z) end else return nil end end def st_basis(dim,n) if n <= dim i = 0 a = Array.new(dim) for i in 0..dim if i == n a = 1 else a = 0 end end return Vector.new(a) else return nil end end def distance(u) x = self - u d = x.magnitude return d end def angle_toUnitVector(θ) return Vector.new([Math.cos(θ),Math.sin(θ)]) end alias angle_toUV angle_toUnitVectorend# A matrix class, unfinished and unused.class Matrix def initialize(mx) #@initialized = true @n_rows = mx[0].length @n_columns = mx.length @matrix = mx end def dimensions return [@n_rows,@n_columns] end def rows return @n_rows end def columns return @n_columns end def entry(i,j) return @matrix[i-1][j-1] end def row(i) return @matrix[i-1] end def column(j) c = Array.new(@n_rows) i = 0 for i in 0..(@n_rows-1) c = @matrix[j-1] end return c end def self.scale(c) for i in 0..(@n_rows-1) for j in 0..(@n_columns-1) self[j] *= c end end end def trace if @n_columns == @n_rows x = 0 for i in 0..(@n_columns-1) x += @matrix end return x end end def minor(x,y) if (x <= @n_rows) && (y <= @n_columns) x -= 1 y -= 1 mat = @matrix mat.delete_at(y) l = @n_columns - 1 i = 0 for i in 0..(l) mat.delete_at(x) end return Matrix.new(mat) end end def determinant if @n_columns == @n_rows if @n_columns == 1 det = @matrix[0][0] elsif @n_columns == 2 det = @matrix[1][1]*@matrix[2][2] - @matrix[1][2]*@matrix[2][1] elsif @n_columns == 3 dm1 = self.entry(2,2)*self.entry(3,3) - self.entry(2,3)*self.entry(3,2) dm2 = self.entry(2,1)*self.entry(3,3) - self.entry(2,3)*self.entry(3,1) dm3 = self.entry(2,1)*self.entry(3,2) - self.entry(2,2)*self.entry(3,1) det = self.entry(1,1)*dm1 - self.entry(1,2)*dm2 +self.entry(1,3)*dm3 end end return det end def singular? if @n_columns == @n_rows if self.det == 0 return true else return false end end end def transform(vector) if self.columns == vector.length() v = Array.new(matrix.rows) i = 0 for i in 0..(matrix.rows-1) r = Vector.new(self.row(i+1)) v = vector * r end return v else return nil end end #def mult(m) #Right multiply # if @n_columns == m.rows # b = Array.new(@n_rows,0) # i = 0 # for i in 0..(@n_rows-1) # b = Array.new(m.columns,0) # end # i = 0 # for i in 0..(@n_rows-1) # j = 0 # for j in 0..(m.columns) # b[j] = Paramecium.dot_product(@matrix,m.column(j) # end # end # return Matrix.new( # endend
Graphs
# Some stuff for graphs. Not finished and not used.class Node attr_accessor :id attr_accessor :value def initialize(id,value) self.id = id self.value = value endendclass Edge attr_accessor :target attr_accessor :weight attr_accessor :value def initialize(target,weight=1,value=nil) self.target = target self.id = id self.weight = weight self.value = value endendex_hash = {"node1" => {:value=>value1, :edges=> [["node2",2,3],["node3",3,"Hi"]] },"node2" => {:value=>value2, :edges=> [["node3",1,nil]]},"node3" => {:value=>value3, :edges=> [["node2",1,nil]]}}class Graph attr_accessor :hash attr_accessor :data def initialize(hash) self.hash = hash self.data = Hash.new self.hash.each_pair{|name,x| self.data[name] = {:node=>Node.new(name,x[:value]),:edges = Array.new} x[:value].each{|edge|self.data[name][:edges].push(Node.new(edge[0],edge[1],edge[2])}}} end def nodes x = Array.new self.data.each_value{|val| x.push(val[:node])} x endendclass ActiveGraph < Graph attr_accessor :currentNode def initialize(hash,start=nil) super(hash) if start && hash[start] self.currentNode = start else self.currentNode = self.data.keys[0] end end def canGoDirectlyTo?(node) x = nil self.data[self.currentNode][:edges].each{|edge| if edge.target == node x = edge.weight end } return x endend
(Not part of Paramecium Core but requires it)
#=================================================================================## This makes damage/healing be normally distributed##=================================================================================class Game_Battler < Game_BattlerBase def apply_variance(damage, variance) var = [damage.abs * variance / 100, 0].max.to_i (Paramecium.nRand(damage,var)).abs endend
- Some method(s) for reading and processing external (text) files. I have yet to write any code for this.
- A dynamic thing that does stuff. I think this has the potential to be very powerful. I wrote an example diagram, a UML class diagram, and some code on some paper.
Ability System
Initial Release: 3/14/2015
The next updates will focus on adding more comments and documentation and expanding and improving the demo.
Upcoming Features
Upcoming Features
- More methods for changing abilities.
- Abilities for overcoming obstacles, where damage is taken on failure.
- Using features from another script I am working on.
Last edited by a moderator: