This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Return a list of functions for attacks. Max roll takes 10% of health. | |
* Other values do that much damage. | |
*/ | |
def attack(numTimes: Int, dieSides: Int): Seq[Int => Int] = | |
for i <- 1 to numTimes yield | |
val d = util.Random.between(1, dieSides + 1) | |
if d == dieSides then | |
(hits: Int) => math.max(d, hits / 10) | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def attack(numTimes, dieSides): | |
""" | |
Return a list of functions for attacks. Max roll takes 10% of health. | |
Other values do that much damage. | |
""" | |
damageFuncs = [] | |
for i in range(1, numTimes): | |
d = random.randint(1, dieSides) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
class Person: | |
age = 5 | |
name = 'hi' | |
def birthday(self): | |
self.age += 1 | |
return self.age |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def readData(filename): | |
f = open(filename, 'r') | |
v1 = int(f.readline()) | |
v2 = f.readline() | |
v3 = f.readline() | |
f.close() | |
return (v1, v2, v3) | |
def mult(x, y): | |
print(x, y) # Added for debugging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def attack(): | |
d1 = random.randint(1, 6) | |
d2 = random.randint(1, 6) | |
n = d1 + d2 | |
if n == 2: | |
n = 'critical miss!' | |
elif n < 8: | |
m = 'weak hit.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalafx.scene.canvas.GraphicsContext | |
import scalafx.scene.image.Image | |
/** | |
* This is a 2D renderer that with draw your game elements to a Canvas. You should change the | |
* images to fit the style of your game. Also, alter the entities to match what you have in | |
* your game. | |
*/ | |
class Renderer2D(gc: GraphicsContext, blockSize: Double) { | |
private var lastCenterX = 0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object MainTiming extends App { | |
def timeCode[T](warmups: Int, timeRuns: Int)(body: => T): Seq[Double] = { | |
for(_ <- 1 to warmups) body | |
for(_ <- 1 to timeRuns) yield { | |
val start = System.nanoTime() | |
body | |
(System.nanoTime()-start)*1e-9 | |
} | |
} | |
def printTimeInfo(times: Seq[Double]): Unit = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<valarray> | |
#include<cmath> | |
#include <chrono> | |
using namespace std; | |
struct MVect3 { | |
double x, y, z; | |
MVect3() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object NBodyFunctional { | |
def initBodies(numBodies: Int): Vector[ImmutableBody] = { | |
Vector.tabulate(numBodies) { i => | |
ImmutableBody(Vect3(i,0,0), Vect3(0,math.sqrt(1.0/i),0), | |
if(i==0) 1 else 1e-10) | |
} | |
} | |
def forSim(bodies: Vector[ImmutableBody], steps: Int, dt: Double): Vector[ImmutableBody] = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object NBodyValClass { | |
private var numBodies = 0 | |
private var dt = 0.0 | |
private var positions = Array.fill(0)(0.0) | |
private var velocities = Array.fill(0)(0.0) | |
private var accel = Array.fill(0)(0.0) | |
private var masses = Array.fill(0)(1e-10) | |
class Particle(val index: Int) extends AnyVal { | |
def x = positions(index*3) |
NewerOlder