/** * @author Richard Davey<EMAIL_ADDRESS>* @copyright 2013 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @class Phaser.Physics */ Phaser.Physics = {}; /** * Arcade Physics constructor. * * @class Phaser.Physics.Arcade * @classdesc Arcade Physics Constructor * @constructor * @param {Phaser.Game} game reference to the current game instance. */ Phaser.Physics.Arcade = function (game) { /** * @property {Phaser.Game} game - Local reference to game. */ this.game = game; /** * @property {Phaser.Point} gravity - The World gravity setting. Defaults to x: 0, y: 0, or no gravity. */ this.gravity = new Phaser.Point(); /** * @property {Phaser.Rectangle} bounds - The bounds inside of which the physics world exists. Defaults to match the world bounds. */ this.bounds = new Phaser.Rectangle(0, 0, game.world.width, game.world.height); /** * @property {number} maxObjects - Used by the QuadTree to set the maximum number of objects per quad. */ this.maxObjects = 10; /** * @property {number} maxLevels - Used by the QuadTree to set the maximum number of iteration levels. */ this.maxLevels = 4; /** * @property {number} OVERLAP_BIAS - A value added to the delta values during collision checks. */ this.OVERLAP_BIAS = 4; /** * @property {Phaser.QuadTree} quadTree - The world QuadTree. */ this.quadTree = new Phaser.QuadTree(this, this.game.world.bounds.x, this.game.world.bounds.y, this.game.world.bounds.width, this.game.world.bounds.height, this.maxObjects, this.maxLevels); /** * @property {number} quadTreeID - The QuadTree ID. */ this.quadTreeID = 0; // Avoid gc spikes by caching these values for re-use /** * @property {Phaser.Rectangle} _bounds1 - Internal cache var. * @private */ this._bounds1 = new Phaser.Rectangle(); /** * @property {Phaser.Rectangle} _bounds2 - Internal cache var. * @private */ this._bounds2 = new Phaser.Rectangle(); /** * @property {number} _overlap - Internal cache var. * @private */ this._overlap = 0; /** * @property {number} _maxOverlap - Internal cache var. * @private */ this._maxOverlap = 0; /** * @property {number} _velocity1 - Internal cache var. * @private */ this._velocity1 = 0; /** * @property {number} _velocity2 - Internal cache var. * @private */ this._velocity2 = 0; /** * @property {number} _newVelocity1 - Internal cache var. * @private */ this._newVelocity1 = 0; /** * @property {number} _newVelocity2 - Internal cache var. * @private */ this._newVelocity2 = 0; /** * @property {number} _average - Internal cache var. * @private */ this._average = 0; /** * @property {Array} _mapData - Internal cache var. * @private */ this._mapData = []; /** * @property {number} _mapTiles - Internal cache var. * @private */ this._mapTiles = 0; /** * @property {boolean} _result - Internal cache var. * @private */ this._result = false; /** * @property {number} _total - Internal cache var. * @private */ this._total = 0; /** * @property {number} _angle - Internal cache var. * @private */ this._angle = 0; /** * @property {number} _dx - Internal cache var. * @private */ this._dx = 0; /** * @property {number} _dy - Internal cache var. * @private */ this._dy = 0; }; Phaser.Physics.Arcade.prototype = { /** * Called automatically by a Physics body, it updates all motion related values on the Body. * * @method Phaser.Physics.Arcade#updateMotion * @param {Phaser.Physics.Arcade.Body} The Body object to be updated. */ updateMotion: function (body) { // If you're wondering why the velocity is halved and applied twice, read this: http://www.niksula.hut.fi/~hkankaan/Homepages/gravity.html // Rotation this._velocityDelta = (this.computeVelocity(0, body, body.angularVelocity, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) * this.game.time.physicsElapsed * 0.5 * 60; body.angularVelocity += this._velocityDelta; body.rotation += (body.angularVelocity * this.game.time.physicsElapsed); body.angularVelocity += this._velocityDelta; // Horizontal this._velocityDelta = (this.computeVelocity(1, body, body.velocity.x, body.acceleration.x, body.drag.x, body.maxVelocity.x) - body.velocity.x) * this.game.time.physicsElapsed * 0.5 * 60; body.velocity.x += this._velocityDelta; body.x += (body.velocity.x * this.game.time.physicsElapsed); body.velocity.x += this._velocityDelta; // Vertical this._velocityDelta = (this.computeVelocity(2, body, body.velocity.y, body.acceleration.y, body.drag.y, body.maxVelocity.y) - body.velocity.y) * this.game.time.physicsElapsed * 0.5 * 60; body.velocity.y += this._velocityDelta; body.y += (body.velocity.y * this.game.time.physicsElapsed); body.velocity.y += this._velocityDelta; }, /** * A tween-like function that takes a starting velocity and some other factors and returns an altered velocity. * * @method Phaser.Physics.Arcade#computeVelocity * @param {number} axis - 1 for horizontal, 2 for vertical. * @param {Phaser.Physics.Arcade.Body} body - The Body object to be updated. * @param {number} velocity - Any component of velocity (e.g. 20). * @param {number} acceleration - Rate at which the velocity is changing. * @param {number} drag - Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set. * @param {number} mMax - An absolute value cap for the velocity. * @return {number} The altered Velocity value. */ computeVelocity: function (axis, body, velocity, acceleration, drag, max) { max = max || 10000; if (axis == 1 && body.allowGravity) { velocity += this.gravity.x + body.gravity.x; } else if (axis == 2 && body.allowGravity) { velocity += this.gravity.y + body.gravity.y; } if (acceleration !== 0) { velocity += acceleration * this.game.time.physicsElapsed; } else if (drag !== 0) { this._drag = drag * this.game.time.physicsElapsed; if (velocity - this._drag > 0) { velocity -= this._drag; } else if (velocity + this._drag < 0) { velocity += this._drag; } else { velocity = 0; } } if (velocity > max) { velocity = max; } else if (velocity < -max) { velocity = -max; } return velocity; }, /** * Called automatically by the core game loop. * * @method Phaser.Physics.Arcade#preUpdate * @protected */ preUpdate: function () { // Clear the tree this.quadTree.clear(); // Create our tree which all of the Physics bodies will add themselves to this.quadTreeID = 0; this.quadTree = new Phaser.QuadTree(this, this.game.world.bounds.x, this.game.world.bounds.y, this.game.world.bounds.width, this.game.world.bounds.height, this.maxObjects, this.maxLevels); }, /** * Called automatically by the core game loop. * * @method Phaser.Physics.Arcade#postUpdate * @protected */ postUpdate: function () { // Clear the tree ready for the next update this.quadTree.clear(); }, /** * Checks for overlaps between two game objects. The objects can be Sprites, Groups or Emitters. * You can perform Sprite vs. Sprite, Sprite vs. Group and Group vs. Group overlap checks. * Unlike collide the objects are NOT automatically separated or have any physics applied, they merely test for overlap results. * * @method Phaser.Physics.Arcade#overlap * @param {Phaser.Sprite|Phaser.Group|Phaser.Particles.Emitter} object1 - The first object to check. Can be an instance of Phaser.Sprite, Phaser.Group or Phaser.Particles.Emitter. * @param {Phaser.Sprite|Phaser.Group|Phaser.Particles.Emitter} object2 - The second object to check. Can be an instance of Phaser.Sprite, Phaser.Group or Phaser.Particles.Emitter. * @param {function} [overlapCallback=null] - An optional callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you specified them. * @param {function} [processCallback=null] - A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then overlapCallback will only be called if processCallback returns true. * @param {object} [callbackContext] - The context in which to run the callbacks. * @returns {boolean} True if an overlap occured otherwise false. */ overlap: function (object1, object2, overlapCallback, processCallback, callbackContext) { overlapCallback = overlapCallback || null; processCallback = processCallback || null; callbackContext = callbackContext || overlapCallback; this._result = false; this._total = 0; // Only test valid objects if (object1 && object2 && object1.exists && object2.exists) { // SPRITES if (object1.type == Phaser.SPRITE) { if (object2.type == Phaser.SPRITE) { this.overlapSpriteVsSprite(object1, object2, overlapCallback, processCallback, callbackContext); } else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER) { this.overlapSpriteVsGroup(object1, object2, overlapCallback, processCallback, callbackContext); } } // GROUPS else if (object1.type == Phaser.GROUP) { if (object2.type == Phaser.SPRITE) { this.overlapSpriteVsGroup(object2, object1, overlapCallback, processCallback, callbackContext); } else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER) { this.overlapGroupVsGroup(object1, object2, overlapCallback, processCallback, callbackContext); } } // EMITTER else if (object1.type == Phaser.EMITTER) { if (object2.type == Phaser.SPRITE) { this.overlapSpriteVsGroup(object2, object1, overlapCallback, processCallback, callbackContext); } else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER) { this.overlapGroupVsGroup(object1, object2, overlapCallback, processCallback, callbackContext); } } } return (this._total > 0); }, /** * An internal function. Use Phaser.Physics.Arcade.overlap instead. * * @method Phaser.Physics.Arcade#overlapSpriteVsSprite * @private */ overlapSpriteVsSprite: function (sprite1, sprite2, overlapCallback, processCallback, callbackContext) { this._result = Phaser.Rectangle.intersects(sprite1.body, sprite2.body); if (this._result) { // They collided, is there a custom process callback? if (processCallback) { if (processCallback.call(callbackContext, sprite1, sprite2)) { this._total++; if (overlapCallback) { overlapCallback.call(callbackContext, sprite1, sprite2); } } } else { this._total++; if (overlapCallback) { overlapCallback.call(callbackContext, sprite1, sprite2); } } } }, /** * An internal function. Use Phaser.Physics.Arcade.overlap instead. * * @method Phaser.Physics.Arcade#overlapSpriteVsGroup * @private */ overlapSpriteVsGroup: function (sprite, group, overlapCallback, processCallback, callbackContext) { if (group.length === 0) { return; } // What is the sprite colliding with in the quadtree? this._potentials = this.quadTree.retrieve(sprite); for (var i = 0, len = this._potentials.length; i < len; i++) { // We have our potential suspects, are they in this group? if (this._potentials[i].sprite.group == group) { this._result = Phaser.Rectangle.intersects(sprite.body, this._potentials[i]); if (this._result && processCallback) { this._result = processCallback.call(callbackContext, sprite, this._potentials[i].sprite); } if (this._result) { this._total++; if (overlapCallback) { overlapCallback.call(callbackContext, sprite, this._potentials[i].sprite); } } } } }, /** * An internal function. Use Phaser.Physics.Arcade.overlap instead. * * @method Phaser.Physics.Arcade#overlapGroupVsGroup * @private */ overlapGroupVsGroup: function (group1, group2, overlapCallback, processCallback, callbackContext) { if (group1.length === 0 || group2.length === 0) { return; } if (group1._container.first._iNext) { var currentNode = group1._container.first._iNext; do { if (currentNode.exists) { this.overlapSpriteVsGroup(currentNode, group2, overlapCallback, processCallback, callbackContext); } currentNode = currentNode._iNext; } while (currentNode != group1._container.last._iNext); } }, /** * Checks for collision between two game objects. The objects can be Sprites, Groups, Emitters or Tilemap Layers. * You can perform Sprite vs. Sprite, Sprite vs. Group, Group vs. Group, Sprite vs. Tilemap Layer or Group vs. Tilemap Layer collisions. * The objects are also automatically separated. * * @method Phaser.Physics.Arcade#collide * @param {Phaser.Sprite|Phaser.Group|Phaser.Particles.Emitter|Phaser.Tilemap} object1 - The first object to check. Can be an instance of Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter, or Phaser.Tilemap * @param {Phaser.Sprite|Phaser.Group|Phaser.Particles.Emitter|Phaser.Tilemap} object2 - The second object to check. Can be an instance of Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter or Phaser.Tilemap * @param {function} [collideCallback=null] - An optional callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you specified them. * @param {function} [processCallback=null] - A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then collideCallback will only be called if processCallback returns true. * @param {object} [callbackContext] - The context in which to run the callbacks. * @returns {boolean} True if a collision occured otherwise false. */ collide: function (object1, object2, collideCallback, processCallback, callbackContext) { collideCallback = collideCallback || null; processCallback = processCallback || null; callbackContext = callbackContext || collideCallback; this._result = false; this._total = 0; // Only collide valid objects if (object1 && object2 && object1.exists && object2.exists) { // Can expand to support Buttons, Text, etc at a later date. For now these are the essentials. // SPRITES if (object1.type == Phaser.SPRITE) { if (object2.type == Phaser.SPRITE) { this.collideSpriteVsSprite(object1, object2, collideCallback, processCallback, callbackContext); } else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER) { this.collideSpriteVsGroup(object1, object2, collideCallback, processCallback, callbackContext); } else if (object2.type == Phaser.TILEMAPLAYER) { this.collideSpriteVsTilemapLayer(object1, object2, collideCallback, processCallback, callbackContext); } } // GROUPS else if (object1.type == Phaser.GROUP) { if (object2.type == Phaser.SPRITE) { this.collideSpriteVsGroup(object2, object1, collideCallback, processCallback, callbackContext); } else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER) { this.collideGroupVsGroup(object1, object2, collideCallback, processCallback, callbackContext); } else if (object2.type == Phaser.TILEMAPLAYER) { this.collideGroupVsTilemapLayer(object1, object2, collideCallback, processCallback, callbackContext); } } // TILEMAP LAYERS else if (object1.type == Phaser.TILEMAPLAYER) { if (object2.type == Phaser.SPRITE) { this.collideSpriteVsTilemapLayer(object2, object1, collideCallback, processCallback, callbackContext); } else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER) { this.collideGroupVsTilemapLayer(object2, object1, collideCallback, processCallback, callbackContext); } } // EMITTER else if (object1.type == Phaser.EMITTER) { if (object2.type == Phaser.SPRITE) { this.collideSpriteVsGroup(object2, object1, collideCallback, processCallback, callbackContext); } else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER) { this.collideGroupVsGroup(object1, object2, collideCallback, processCallback, callbackContext); } else if (object2.type == Phaser.TILEMAPLAYER) { this.collideGroupVsTilemapLayer(object1, object2, collideCallback, processCallback, callbackContext); } } } return (this._total > 0); }, /** * An internal function. Use Phaser.Physics.Arcade.collide instead. * * @method Phaser.Physics.Arcade#collideSpriteVsTilemapLayer * @private */ collideSpriteVsTilemapLayer: function (sprite, tilemapLayer, collideCallback, processCallback, callbackContext) { this._mapData = tilemapLayer.getTiles(sprite.body.x, sprite.body.y, sprite.body.width, sprite.body.height, true); if (this._mapData.length === 0) { return; } for (var i = 0; i < this._mapData.length; i++) { if (this.separateTile(sprite.body, this._mapData[i])) { // They collided, is there a custom process callback? if (processCallback) { if (processCallback.call(callbackContext, sprite, this._mapData[i])) { this._total++; if (collideCallback) { collideCallback.call(callbackContext, sprite, this._mapData[i]); } } } else { this._total++; if (collideCallback) { collideCallback.call(callbackContext, sprite, this._mapData[i]); } } } } }, /** * An internal function. Use Phaser.Physics.Arcade.collide instead. * * @method Phaser.Physics.Arcade#collideGroupVsTilemapLayer * @private */ collideGroupVsTilemapLayer: function (group, tilemapLayer, collideCallback, processCallback, callbackContext) { if (group.length === 0) { return; } if (group.length === 0) { return; } if (group._container.first._iNext) { var currentNode = group._container.first._iNext; do { if (currentNode.exists) { this.collideSpriteVsTilemapLayer(currentNode, tilemapLayer, collideCallback, processCallback, callbackContext); } currentNode = currentNode._iNext; } while (currentNode != group._container.last._iNext); } }, /** * An internal function. Use Phaser.Physics.Arcade.collide instead. * * @method Phaser.Physics.Arcade#collideSpriteVsSprite * @private */ collideSpriteVsSprite: function (sprite1, sprite2, collideCallback, processCallback, callbackContext) { this.separate(sprite1.body, sprite2.body); if (this._result) { // They collided, is there a custom process callback? if (processCallback) { if (processCallback.call(callbackContext, sprite1, sprite2)) { this._total++; if (collideCallback) { collideCallback.call(callbackContext, sprite1, sprite2); } } } else { this._total++; if (collideCallback) { collideCallback.call(callbackContext, sprite1, sprite2); } } } }, /** * An internal function. Use Phaser.Physics.Arcade.collide instead. * * @method Phaser.Physics.Arcade#collideSpriteVsGroup * @private */ collideSpriteVsGroup: function (sprite, group, collideCallback, processCallback, callbackContext) { if (group.length === 0) { return; } // What is the sprite colliding with in the quadtree? this._potentials = this.quadTree.retrieve(sprite); for (var i = 0, len = this._potentials.length; i < len; i++) { // We have our potential suspects, are they in this group? if (this._potentials[i].sprite.group == group) { this.separate(sprite.body, this._potentials[i]); if (this._result && processCallback) { this._result = processCallback.call(callbackContext, sprite, this._potentials[i].sprite); } if (this._result) { this._total++; if (collideCallback) { collideCallback.call(callbackContext, sprite, this._potentials[i].sprite); } } } } }, /** * An internal function. Use Phaser.Physics.Arcade.collide instead. * * @method Phaser.Physics.Arcade#collideGroupVsGroup * @private */ collideGroupVsGroup: function (group1, group2, collideCallback, processCallback, callbackContext) { if (group1.length === 0 || group2.length === 0) { return; } if (group1._container.first._iNext) { var currentNode = group1._container.first._iNext; do { if (currentNode.exists) { this.collideSpriteVsGroup(currentNode, group2, collideCallback, processCallback, callbackContext); } currentNode = currentNode._iNext; } while (currentNode != group1._container.last._iNext); } }, /** * The core separation function to separate two physics bodies. * @method Phaser.Physics.Arcade#separate * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate. * @param {Phaser.Physics.Arcade.Body} body2 - The Body object to separate. * @returns {boolean} Returns true if the bodies were separated, otherwise false. */ separate: function (body1, body2) { this._result = (this.separateX(body1, body2) || this.separateY(body1, body2)); }, /** * The core separation function to separate two physics bodies on the x axis. * @method Phaser.Physics.Arcade#separateX * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate. * @param {Phaser.Physics.Arcade.Body} body2 - The Body object to separate. * @returns {boolean} Returns true if the bodies were separated, otherwise false. */ separateX: function (body1, body2) { // Can't separate two immovable bodies if (body1.immovable && body2.immovable) { return false; } this._overlap = 0; // Check if the hulls actually overlap if (Phaser.Rectangle.intersects(body1, body2)) { this._maxOverlap = body1.deltaAbsX() + body2.deltaAbsX() + this.OVERLAP_BIAS; if (body1.deltaX() === 0 && body2.deltaX() === 0) { // They overlap but neither of them are moving body1.embedded = true; body2.embedded = true; } else if (body1.deltaX() > body2.deltaX()) { // Body1 is moving right and/or Body2 is moving left this._overlap = body1.x + body1.width - body2.x; if ((this._overlap > this._maxOverlap) || body1.allowCollision.right === false || body2.allowCollision.left === false) { this._overlap = 0; } else { body1.touching.right = true; body2.touching.left = true; } } else if (body1.deltaX() < body2.deltaX()) { // Body1 is moving left and/or Body2 is moving right this._overlap = body1.x - body2.width - body2.x; if ((-this._overlap > this._maxOverlap) || body1.allowCollision.left === false || body2.allowCollision.right === false) { this._overlap = 0; } else { body1.touching.left = true; body2.touching.right = true; } } // Then adjust their positions and velocities accordingly (if there was any overlap) if (this._overlap !== 0) { body1.overlapX = this._overlap; body2.overlapX = this._overlap; if (body1.customSeparateX || body2.customSeparateX) { return true; } this._velocity1 = body1.velocity.x; this._velocity2 = body2.velocity.x; if (!body1.immovable && !body2.immovable) { this._overlap *= 0.5; body1.x = body1.x - this._overlap; body2.x += this._overlap; this._newVelocity1 = Math.sqrt((this._velocity2 * this._velocity2 * body2.mass) / body1.mass) * ((this._velocity2 > 0) ? 1 : -1); this._newVelocity2 = Math.sqrt((this._velocity1 * this._velocity1 * body1.mass) / body2.mass) * ((this._velocity1 > 0) ? 1 : -1); this._average = (this._newVelocity1 + this._newVelocity2) * 0.5; this._newVelocity1 -= this._average; this._newVelocity2 -= this._average; body1.velocity.x = this._average + this._newVelocity1 * body1.bounce.x; body2.velocity.x = this._average + this._newVelocity2 * body2.bounce.x; } else if (!body1.immovable) { body1.x = body1.x - this._overlap; body1.velocity.x = this._velocity2 - this._velocity1 * body1.bounce.x; } else if (!body2.immovable) { body2.x += this._overlap; body2.velocity.x = this._velocity1 - this._velocity2 * body2.bounce.x; } body1.updateHulls(); body2.updateHulls(); return true; } } return false; }, /** * The core separation function to separate two physics bodies on the y axis. * @method Phaser.Physics.Arcade#separateY * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate. * @param {Phaser.Physics.Arcade.Body} body2 - The Body object to separate. * @returns {boolean} Returns true if the bodies were separated, otherwise false. */ separateY: function (body1, body2) { // Can't separate two immovable or non-existing bodys if (body1.immovable && body2.immovable) { return false; } this._overlap = 0; // Check if the hulls actually overlap if (Phaser.Rectangle.intersects(body1, body2)) { this._maxOverlap = body1.deltaAbsY() + body2.deltaAbsY() + this.OVERLAP_BIAS; if (body1.deltaY() === 0 && body2.deltaY() === 0) { // They overlap but neither of them are moving body1.embedded = true; body2.embedded = true; } else if (body1.deltaY() > body2.deltaY()) { // Body1 is moving down and/or Body2 is moving up this._overlap = body1.y + body1.height - body2.y; if ((this._overlap > this._maxOverlap) || body1.allowCollision.down === false || body2.allowCollision.up === false) { this._overlap = 0; } else { body1.touching.down = true; body2.touching.up = true; } } else if (body1.deltaY() < body2.deltaY()) { // Body1 is moving up and/or Body2 is moving down this._overlap = body1.y - body2.height - body2.y; if ((-this._overlap > this._maxOverlap) || body1.allowCollision.up === false || body2.allowCollision.down === false) { this._overlap = 0; } else { body1.touching.up = true; body2.touching.down = true; } } // Then adjust their positions and velocities accordingly (if there was any overlap) if (this._overlap !== 0) { body1.overlapY = this._overlap; body2.overlapY = this._overlap; if (body1.customSeparateY || body2.customSeparateY) { return true; } this._velocity1 = body1.velocity.y; this._velocity2 = body2.velocity.y; if (!body1.immovable && !body2.immovable) { this._overlap *= 0.5; body1.y = body1.y - this._overlap; body2.y += this._overlap; this._newVelocity1 = Math.sqrt((this._velocity2 * this._velocity2 * body2.mass) / body1.mass) * ((this._velocity2 > 0) ? 1 : -1); this._newVelocity2 = Math.sqrt((this._velocity1 * this._velocity1 * body1.mass) / body2.mass) * ((this._velocity1 > 0) ? 1 : -1); this._average = (this._newVelocity1 + this._newVelocity2) * 0.5; this._newVelocity1 -= this._average; this._newVelocity2 -= this._average; body1.velocity.y = this._average + this._newVelocity1 * body1.bounce.y; body2.velocity.y = this._average + this._newVelocity2 * body2.bounce.y; } else if (!body1.immovable) { body1.y = body1.y - this._overlap; body1.velocity.y = this._velocity2 - this._velocity1 * body1.bounce.y; // This is special case code that handles things like horizontal moving platforms you can ride if (body2.active && body2.moves && (body1.deltaY() > body2.deltaY())) { body1.x += body2.x - body2.lastX; } } else if (!body2.immovable) { body2.y += this._overlap; body2.velocity.y = this._velocity1 - this._velocity2 * body2.bounce.y; // This is special case code that handles things like horizontal moving platforms you can ride if (body1.sprite.active && body1.moves && (body1.deltaY() < body2.deltaY())) { body2.x += body1.x - body1.lastX; } } body1.updateHulls(); body2.updateHulls(); return true; } } return false; }, /** * The core separation function to separate a physics body and a tile. * @method Phaser.Physics.Arcade#separateTile * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate. * @param {Phaser.Tile} tile - The tile to collide against. * @returns {boolean} Returns true if the bodies were separated, otherwise false. */ separateTile: function (body, tile) { this._result = (this.separateTileX(body, tile, true) || this.separateTileY(body, tile, true)); return this._result; }, /** * The core separation function to separate a physics body and a tile on the x axis. * @method Phaser.Physics.Arcade#separateTileX * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate. * @param {Phaser.Tile} tile - The tile to collide against. * @returns {boolean} Returns true if the bodies were separated, otherwise false. */ separateTileX: function (body, tile, separate) { // Can't separate two immovable objects (tiles are always immovable) if (body.immovable || body.deltaX() === 0 || Phaser.Rectangle.intersects(body.hullX, tile) === false) { return false; } this._overlap = 0; // The hulls overlap, let's process it // this._maxOverlap = body.deltaAbsX() + this.OVERLAP_BIAS; if (body.deltaX() < 0) { // Moving left this._overlap = tile.right - body.hullX.x; // if ((this._overlap > this._maxOverlap) || body.allowCollision.left === false || tile.tile.collideRight === false) if (body.allowCollision.left === false || tile.tile.collideRight === false) { this._overlap = 0; } else { body.touching.left = true; } } else { // Moving right this._overlap = body.hullX.right - tile.x; // if ((this._overlap > this._maxOverlap) || body.allowCollision.right === false || tile.tile.collideLeft === false) if (body.allowCollision.right === false || tile.tile.collideLeft === false) { this._overlap = 0; } else { body.touching.right = true; } } // Then adjust their positions and velocities accordingly (if there was any overlap) if (this._overlap !== 0) { if (separate) { if (body.deltaX() < 0) { body.x = body.x + this._overlap; } else { body.x = body.x - this._overlap; } if (body.bounce.x === 0) { body.velocity.x = 0; } else { body.velocity.x = -body.velocity.x * body.bounce.x; } body.updateHulls(); } return true; } else { return false; } }, /** * The core separation function to separate a physics body and a tile on the x axis. * @method Phaser.Physics.Arcade#separateTileY * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate. * @param {Phaser.Tile} tile - The tile to collide against. * @returns {boolean} Returns true if the bodies were separated, otherwise false. */ separateTileY: function (body, tile, separate) { // Can't separate two immovable objects (tiles are always immovable) if (body.immovable || body.deltaY() === 0 || Phaser.Rectangle.intersects(body.hullY, tile) === false) { return false; } this._overlap = 0; // The hulls overlap, let's process it // this._maxOverlap = body.deltaAbsY() + this.OVERLAP_BIAS; if (body.deltaY() < 0) { // Moving up this._overlap = tile.bottom - body.hullY.y; // if ((this._overlap > this._maxOverlap) || body.allowCollision.up === false || tile.tile.collideDown === false) if (body.allowCollision.up === false || tile.tile.collideDown === false) { this._overlap = 0; } else { body.touching.up = true; } } else { // Moving down this._overlap = body.hullY.bottom - tile.y; // if ((this._overlap > this._maxOverlap) || body.allowCollision.down === false || tile.tile.collideUp === false) if (body.allowCollision.down === false || tile.tile.collideUp === false) { this._overlap = 0; } else { body.touching.down = true; } } // Then adjust their positions and velocities accordingly (if there was any overlap) if (this._overlap !== 0) { if (separate) { if (body.deltaY() < 0) { body.y = body.y + this._overlap; } else { body.y = body.y - this._overlap; } if (body.bounce.y === 0) { body.velocity.y = 0; } else { body.velocity.y = -body.velocity.y * body.bounce.y; } body.updateHulls(); } return true; } else { return false; } }, /** * Move the given display object towards the destination object at a steady velocity. * If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds. * Timings are approximate due to the way browser timers work. Allow for a variance of +- 50ms. * Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course. * Note: The display object doesn't stop moving once it reaches the destination coordinates. * Note: Doesn't take into account acceleration, maxVelocity or drag (if you've set drag or acceleration too high this object may not move at all) * * @method Phaser.Physics.Arcade#moveToObject * @param {any} displayObject - The display object to move. * @param {any} destination - The display object to move towards. Can be any object but must have visible x/y properties. * @param {number} [speed=60] - The speed it will move, in pixels per second (default is 60 pixels/sec) * @param {number} [maxTime=0] - Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms. * @return {number} The angle (in radians) that the object should be visually set to in order to match its new velocity. */ moveToObject: function (displayObject, destination, speed, maxTime) { if (typeof speed === 'undefined') { speed = 60; } if (typeof maxTime === 'undefined') { maxTime = 0; } this._angle = Math.atan2(destination.y - displayObject.y, destination.x - displayObject.x); if (maxTime > 0) { // We know how many pixels we need to move, but how fast? speed = this.distanceBetween(displayObject, destination) / (maxTime / 1000); } displayObject.body.velocity.x = Math.cos(this._angle) * speed; displayObject.body.velocity.y = Math.sin(this._angle) * speed; return this._angle; }, /** * Move the given display object towards the pointer at a steady velocity. If no pointer is given it will use Phaser.Input.activePointer. * If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds. * Timings are approximate due to the way browser timers work. Allow for a variance of +- 50ms. * Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course. * Note: The display object doesn't stop moving once it reaches the destination coordinates. * * @method Phaser.Physics.Arcade#moveToPointer * @param {any} displayObject - The display object to move. * @param {number} [speed=60] - The speed it will move, in pixels per second (default is 60 pixels/sec) * @param {Phaser.Pointer} [pointer] - The pointer to move towards. Defaults to Phaser.Input.activePointer. * @param {number} [maxTime=0] - Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms. * @return {number} The angle (in radians) that the object should be visually set to in order to match its new velocity. */ moveToPointer: function (displayObject, speed, pointer, maxTime) { if (typeof speed === 'undefined') { speed = 60; } pointer = pointer || this.game.input.activePointer; if (typeof maxTime === 'undefined') { maxTime = 0; } this._angle = this.angleToPointer(displayObject, pointer); if (maxTime > 0) { // We know how many pixels we need to move, but how fast? speed = this.distanceToPointer(displayObject, pointer) / (maxTime / 1000); } displayObject.body.velocity.x = Math.cos(this._angle) * speed; displayObject.body.velocity.y = Math.sin(this._angle) * speed; return this._angle; }, /** * Move the given display object towards the x/y coordinates at a steady velocity. * If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds. * Timings are approximate due to the way browser timers work. Allow for a variance of +- 50ms. * Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course. * Note: The display object doesn't stop moving once it reaches the destination coordinates. * Note: Doesn't take into account acceleration, maxVelocity or drag (if you've set drag or acceleration too high this object may not move at all) * * @method Phaser.Physics.Arcade#moveToXY * @param {any} displayObject - The display object to move. * @param {number} x - The x coordinate to move towards. * @param {number} y - The y coordinate to move towards. * @param {number} [speed=60] - The speed it will move, in pixels per second (default is 60 pixels/sec) * @param {number} [maxTime=0] - Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms. * @return {number} The angle (in radians) that the object should be visually set to in order to match its new velocity. */ moveToXY: function (displayObject, x, y, speed, maxTime) { if (typeof speed === 'undefined') { speed = 60; } if (typeof maxTime === 'undefined') { maxTime = 0; } this._angle = Math.atan2(y - displayObject.y, x - displayObject.x); if (maxTime > 0) { // We know how many pixels we need to move, but how fast? speed = this.distanceToXY(displayObject, x, y) / (maxTime / 1000); } displayObject.body.velocity.x = Math.cos(this._angle) * speed; displayObject.body.velocity.y = Math.sin(this._angle) * speed; return this._angle; }, /** * Given the angle (in degrees) and speed calculate the velocity and return it as a Point object, or set it to the given point object. * One way to use this is: velocityFromAngle(angle, 200, sprite.velocity) which will set the values directly to the sprites velocity and not create a new Point object. * * @method Phaser.Physics.Arcade#velocityFromAngle * @param {number} angle - The angle in degrees calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative) * @param {number} [speed=60] - The speed it will move, in pixels per second sq. * @param {Phaser.Point|object} [point] - The Point object in which the x and y properties will be set to the calculated velocity. * @return {Phaser.Point} - A Point where point.x contains the velocity x value and point.y contains the velocity y value. */ velocityFromAngle: function (angle, speed, point) { if (typeof speed === 'undefined') { speed = 60; } point = point || new Phaser.Point(); return point.setTo((Math.cos(this.game.math.degToRad(angle)) * speed), (Math.sin(this.game.math.degToRad(angle)) * speed)); }, /** * Given the rotation (in radians) and speed calculate the velocity and return it as a Point object, or set it to the given point object. * One way to use this is: velocityFromRotation(rotation, 200, sprite.velocity) which will set the values directly to the sprites velocity and not create a new Point object. * * @method Phaser.Physics.Arcade#velocityFromRotation * @param {number} rotation - The angle in radians. * @param {number} [speed=60] - The speed it will move, in pixels per second sq. * @param {Phaser.Point|object} [point] - The Point object in which the x and y properties will be set to the calculated velocity. * @return {Phaser.Point} - A Point where point.x contains the velocity x value and point.y contains the velocity y value. */ velocityFromRotation: function (rotation, speed, point) { if (typeof speed === 'undefined') { speed = 60; } point = point || new Phaser.Point(); return point.setTo((Math.cos(rotation) * speed), (Math.sin(rotation) * speed)); }, /** * Given the rotation (in radians) and speed calculate the acceleration and return it as a Point object, or set it to the given point object. * One way to use this is: velocityFromRotation(rotation, 200, sprite.velocity) which will set the values directly to the sprites velocity and not create a new Point object. * * @method Phaser.Physics.Arcade#accelerationFromRotation * @param {number} rotation - The angle in radians. * @param {number} [speed=60] - The speed it will move, in pixels per second sq. * @param {Phaser.Point|object} [point] - The Point object in which the x and y properties will be set to the calculated acceleration. * @return {Phaser.Point} - A Point where point.x contains the acceleration x value and point.y contains the acceleration y value. */ accelerationFromRotation: function (rotation, speed, point) { if (typeof speed === 'undefined') { speed = 60; } point = point || new Phaser.Point(); return point.setTo((Math.cos(rotation) * speed), (Math.sin(rotation) * speed)); }, /** * Sets the acceleration.x/y property on the display object so it will move towards the target at the given speed (in pixels per second sq.) * You must give a maximum speed value, beyond which the display object won't go any faster. * Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course. * Note: The display object doesn't stop moving once it reaches the destination coordinates. * * @method Phaser.Physics.Arcade#accelerateToObject * @param {any} displayObject - The display object to move. * @param {any} destination - The display object to move towards. Can be any object but must have visible x/y properties. * @param {number} [speed=60] - The speed it will accelerate in pixels per second. * @param {number} [xSpeedMax=500] - The maximum x velocity the display object can reach. * @param {number} [ySpeedMax=500] - The maximum y velocity the display object can reach. * @return {number} The angle (in radians) that the object should be visually set to in order to match its new trajectory. */ accelerateToObject: function (displayObject, destination, speed, xSpeedMax, ySpeedMax) { if (typeof speed === 'undefined') { speed = 60; } if (typeof xSpeedMax === 'undefined') { xSpeedMax = 1000; } if (typeof ySpeedMax === 'undefined') { ySpeedMax = 1000; } this._angle = this.angleBetween(displayObject, destination); displayObject.body.acceleration.setTo(Math.cos(this._angle) * speed, Math.sin(this._angle) * speed); displayObject.body.maxVelocity.setTo(xSpeedMax, ySpeedMax); return this._angle; }, /** * Sets the acceleration.x/y property on the display object so it will move towards the target at the given speed (in pixels per second sq.) * You must give a maximum speed value, beyond which the display object won't go any faster. * Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course. * Note: The display object doesn't stop moving once it reaches the destination coordinates. * * @method Phaser.Physics.Arcade#accelerateToPointer * @param {any} displayObject - The display object to move. * @param {Phaser.Pointer} [pointer] - The pointer to move towards. Defaults to Phaser.Input.activePointer. * @param {number} [speed=60] - The speed it will accelerate in pixels per second. * @param {number} [xSpeedMax=500] - The maximum x velocity the display object can reach. * @param {number} [ySpeedMax=500] - The maximum y velocity the display object can reach. * @return {number} The angle (in radians) that the object should be visually set to in order to match its new trajectory. */ accelerateToPointer: function (displayObject, pointer, speed, xSpeedMax, ySpeedMax) { if (typeof speed === 'undefined') { speed = 60; } if (typeof pointer === 'undefined') { pointer = this.game.input.activePointer; } if (typeof xSpeedMax === 'undefined') { xSpeedMax = 1000; } if (typeof ySpeedMax === 'undefined') { ySpeedMax = 1000; } this._angle = this.angleToPointer(displayObject, pointer); displayObject.body.acceleration.setTo(Math.cos(this._angle) * speed, Math.sin(this._angle) * speed); displayObject.body.maxVelocity.setTo(xSpeedMax, ySpeedMax); return this._angle; }, /** * Sets the acceleration.x/y property on the display object so it will move towards the x/y coordinates at the given speed (in pixels per second sq.) * You must give a maximum speed value, beyond which the display object won't go any faster. * Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course. * Note: The display object doesn't stop moving once it reaches the destination coordinates. * * @method Phaser.Physics.Arcade#accelerateToXY * @param {any} displayObject - The display object to move. * @param {number} x - The x coordinate to accelerate towards. * @param {number} y - The y coordinate to accelerate towards. * @param {number} [speed=60] - The speed it will accelerate in pixels per second. * @param {number} [xSpeedMax=500] - The maximum x velocity the display object can reach. * @param {number} [ySpeedMax=500] - The maximum y velocity the display object can reach. * @return {number} The angle (in radians) that the object should be visually set to in order to match its new trajectory. */ accelerateToXY: function (displayObject, x, y, speed, xSpeedMax, ySpeedMax) { if (typeof speed === 'undefined') { speed = 60; } if (typeof xSpeedMax === 'undefined') { xSpeedMax = 1000; } if (typeof ySpeedMax === 'undefined') { ySpeedMax = 1000; } this._angle = this.angleToXY(displayObject, x, y); displayObject.body.acceleration.setTo(Math.cos(this._angle) * speed, Math.sin(this._angle) * speed); displayObject.body.maxVelocity.setTo(xSpeedMax, ySpeedMax); return this._angle; }, /** * Find the distance between two display objects (like Sprites). * * @method Phaser.Physics.Arcade#distanceBetween * @param {any} source - The Display Object to test from. * @param {any} target - The Display Object to test to. * @return {number} The distance between the source and target objects. */ distanceBetween: function (source, target) { this._dx = source.x - target.x; this._dy = source.y - target.y; return Math.sqrt(this._dx * this._dx + this._dy * this._dy); }, /** * Find the distance between a display object (like a Sprite) and the given x/y coordinates. * The calculation is made from the display objects x/y coordinate. This may be the top-left if its anchor hasn't been changed. * If you need to calculate from the center of a display object instead use the method distanceBetweenCenters() * * @method Phaser.Physics.Arcade#distanceToXY * @param {any} displayObject - The Display Object to test from. * @param {number} x - The x coordinate to move towards. * @param {number} y - The y coordinate to move towards. * @return {number} The distance between the object and the x/y coordinates. */ distanceToXY: function (displayObject, x, y) { this._dx = displayObject.x - x; this._dy = displayObject.y - y; return Math.sqrt(this._dx * this._dx + this._dy * this._dy); }, /** * Find the distance between a display object (like a Sprite) and a Pointer. If no Pointer is given the Input.activePointer is used. * The calculation is made from the display objects x/y coordinate. This may be the top-left if its anchor hasn't been changed. * If you need to calculate from the center of a display object instead use the method distanceBetweenCenters() * * @method Phaser.Physics.Arcade#distanceToPointer * @param {any} displayObject - The Display Object to test from. * @param {Phaser.Pointer} [pointer] - The Phaser.Pointer to test to. If none is given then Input.activePointer is used. * @return {number} The distance between the object and the Pointer. */ distanceToPointer: function (displayObject, pointer) { pointer = pointer || this.game.input.activePointer; this._dx = displayObject.x - pointer.x; this._dy = displayObject.y - pointer.y; return Math.sqrt(this._dx * this._dx + this._dy * this._dy); }, /** * Find the angle in radians between two display objects (like Sprites). * * @method Phaser.Physics.Arcade#angleBetween * @param {any} source - The Display Object to test from. * @param {any} target - The Display Object to test to. * @return {number} The angle in radians between the source and target display objects. */ angleBetween: function (source, target) { this._dx = target.x - source.x; this._dy = target.y - source.y; return Math.atan2(this._dy, this._dx); }, /** * Find the angle in radians between a display object (like a Sprite) and the given x/y coordinate. * * @method Phaser.Physics.Arcade#angleToXY * @param {any} displayObject - The Display Object to test from. * @param {number} x - The x coordinate to get the angle to. * @param {number} y - The y coordinate to get the angle to. * @return {number} The angle in radians between displayObject.x/y to Pointer.x/y */ angleToXY: function (displayObject, x, y) { this._dx = x - displayObject.x; this._dy = y - displayObject.y; return Math.atan2(this._dy, this._dx); }, /** * Find the angle in radians between a display object (like a Sprite) and a Pointer, taking their x/y and center into account. * * @method Phaser.Physics.Arcade#angleToPointer * @param {any} displayObject - The Display Object to test from. * @param {Phaser.Pointer} [pointer] - The Phaser.Pointer to test to. If none is given then Input.activePointer is used. * @return {number} The angle in radians between displayObject.x/y to Pointer.x/y */ angleToPointer: function (displayObject, pointer) { pointer = pointer || this.game.input.activePointer; this._dx = pointer.worldX - displayObject.x; this._dy = pointer.worldY - displayObject.y; return Math.atan2(this._dy, this._dx); } };


CommunityConnect
Meet the Team
Tim Silby
Database design. Likes helping people.
Nina Welsh
Worked on the Front end of the application.
Colin Smith
Middleware, marketing and PR. He's a really nice guy.
Rory Tanner
App Founder, Front-end Development & Deployment.


INX Media Case: No Relief For Chidambaram, Court Says Bail Will Send 'Wrong Message'
Justice Suresh Kait said a wrong message will be sent to the society if bail is granted to Chidambaram.
by PTIThe Delhi High Court on Friday denied bail to former finance minister P Chidambaram in the INX Media money laundering case filed by the Enforcement Directorate, saying prima facie allegations against him are serious in nature and he played an active and key role in the offence.
Justice Suresh Kait said that wrong message will be sent to the society if bail is granted to Chidambaram in this case.
The high court had reserved the order on November 8 on the bail petition after hearing the arguments of counsel for Chidambaram and the Enforcement Directorate (ED).
The ED had arrested him in the money laundering case on October 16.
Chidambaram was arrested by the CBI on August 21 in the INX Media corruption case and was granted bail by the Supreme Court on October 22.
The case was registered by the CBI on May 15, 2017, alleging irregularities in a Foreign Investment Promotion Board (FIPB) clearance granted to the INX Media group for receiving overseas funds of Rs 305 crore in 2007, during Chidambaram's tenure as finance minister.
Thereafter, the ED had lodged a money-laundering case in this regard in 2017.


Research
Multimedia Communication
Related Publications
-
Jie Ren, Mai Xu*, Wei Chen, Zhiguo Ding and Zulin Wang: Coalition Formation Approaches for Cooperative Networks with SWIPT, IEEE ACCESS, 5, 2017.
-
Kanapathippillai Cumanan, Zhiguo Ding, Mai Xu*, Vincent Poor, Secrecy Rate Optimization for Secure Multicast Communications, IEEE Journal of Selected Topics on Signal Processing, 10(8), 2016.
-
Cheng Zhu, Kanapathippillai Cumanan, Mai Xu, and Zhiguo Ding, Robust secrecy rate optimisations for multiuser multiple-input-single-output channel with device-to-device communications, IET Communications, 9(3), 2015.
-
Zhiguo Ding, Mai Xu, Bayan Sharif and Jianhua Lu: A General Transmission Scheme for Bi-directional Communication by Using Eigenmode Sharing, IEEE Journal on Selected Areas in Communications (JASC), 30(8), 2012.
-
Zhiguo Ding, Mai Xu, Jianhua Lu and Fei Liu: Improving Wireless Security for Bi-directional Communication Scenarios, IEEE Transactions on Vehicular Technology, 2012.
-
Zhao Chen, Liuguo Yin, Mai Xu and Jianhua Lu: Layered Multimedia Broadcast using Rateless Codes with Progressive Recovery over Cooperative MIMO, EURASIP Journal on Wireless Communications and Networking, 2012.


User roles
Create new user role
The order in which user roles appear here reflect their level; roles higher in this list can assign users to roles lower down, and certain functionality within the system will be available based on these levels. Use the arrows to adjust these levels.
Use caution when adjusting the user role levels. Changes will take effect immediately.
| Name | Users | |||
|---|---|---|---|---|
|
|
{{ role.name }} | {{ role.users_count }} |
|


This application helps you find out the day of the week that you were born and then gives you your Akan name based on your gender.
Akan names are derived from Ghanian culture. Frequently in Ghana, children are given their first name as a 'day name' which corresponds
to the day in the week they were born.


My Site
Open the console
Get Person from server
Set new last name
Add Pet
Add Trait
Set LastEdited
Send Person to server
Output


--- layout: page title: "About" header-img: "img/bg/about-bg.jpg" ---
Hi, my name is Siyuan Gao (高思远). My first name is pronounced pretty much as See Young, but it's still hard to remember, so you are also welcome to call me Ricky.
I was born in Shandong Province, China, and left my hometown for college in Hangzhou, China, where I finished my bachelor degree in Zhejiang University. Zhejiang University is one of the most prestigious universities in China. For now, I am a Ph.D. student at Yale Univeristy . Besides looking at my CV or research, please also kindly check out my online gallery where all my awkward photographs are posted.


|
Genetic Algorithms
A genetic algorithm can be really easy to implement. I made it a little harder for myself by creating a generic library in stead of a domain specific algorithm for some specific problem. My aim is to build tools to be used again. What was implemented:
What was not implemented:
Actually, this implementation is generic, but very limited. The possibilities of extending and modifying a genetic algorithm are large. I made a consideration between studying long on this subject to gain deeper insight in its intricacies, and moving on to other subjects and I chose the latter, because its more important to me now to gain a wide understanding of available AI techniques. I do believe that my architecture may be extended without to much hardship. Remarks
Sample use
This sample solves the n-Queens problem. As you can see, the domain specific class takes up most of the space. class CQueenGenome: public CGeneticGenome { protected: int n; int *y; public: CQueenGenome(int new_n) { n = new_n; y = new int[n]; } ~CQueenGenome(){ delete[] y; } /// create a new genome, no randomization is required virtual CGeneticGenome *NewGenome(){ return new CQueenGenome(n); } /// create default (random) values for the genes virtual void Initialize() { for (int i=0; i<n; i++) MutateGene(i); } /// set the length (i.e. the number of genes) virtual void SetLength(int NewLength){} /// return the length virtual int GetLength(void){ return n; } /// copy gene at position Pos to Child at pos ChildPos virtual void CopyGene(int Pos, CGeneticGenome *Child, int ChildPos) { ((CQueenGenome *)Child)->y[ChildPos] = y[Pos]; } /// is this genome equal to Genome virtual bool Equals(CGeneticGenome *Genome) { for (int i=0; i<n; i++) { if (y[i] != ((CQueenGenome *)Genome)->y[i]) return false; } return true; } /// store a random value in the gene virtual void MutateGene(int GeneIndex) { int old_y, new_y; old_y = y[GeneIndex]; do { new_y = CMath::GetRandomInt(0, n-1); } while (new_y == old_y); y[GeneIndex] = new_y; } /// calculate and return the fitness of this genome virtual void CalculateFitness(void) { int piece, piece_x, piece_y, pos_x, pos_y; Fitness = 0.0f; for(piece=0; piece<n; piece++) { piece_x = piece; piece_y = y[piece]; // horizontal right for(pos_x = piece_x+1, pos_y = piece_y; pos_x < n; pos_x++) { if (y[pos_x] == pos_y){ Fitness--; } } // horizontal left for(pos_x = piece_x-1, pos_y = piece_y; pos_x >= 0; pos_x--) { if (y[pos_x] == pos_y){ Fitness--; } } // right up for(pos_x = piece_x+1, pos_y = piece_y+1; (pos_y < n) && (pos_x < n); pos_y++, pos_x++) { if (y[pos_x] == pos_y){ Fitness--; } } // right down for(pos_x = piece_x+1, pos_y = piece_y-1; (pos_y >= 0) && (pos_x < n); pos_y--, pos_x++) { if (y[pos_x] == pos_y){ Fitness--; } } // left up for(pos_x = piece_x-1, pos_y = piece_y+1; (pos_y < n) && (pos_x >= 0); pos_y++, pos_x--) { if (y[pos_x] == pos_y){ Fitness--; } } // left down for(pos_x = piece_x-1, pos_y = piece_y-1; (pos_y >= 0) && (pos_x >= 0); pos_y--, pos_x--) { if (y[pos_x] == pos_y){ Fitness--; } } } Fitness = 1.0f + (Fitness / (2 * n)); if (Fitness < 0.0) Fitness = 0.0f; } /// is the genome fit enough to stop evolving? virtual bool IsFitEnough(void) { return (Fitness == 1.0f); } virtual const CString ToString(void) const { CString String; for (int i=0; i<n; i++) { String += y[i]; String += ' '; } return String; } }; int main(int argc, char* argv[]) { // genetic algorithms CQueenGenome QueenGenome(100); CGeneticModel GeneticModel(&QueenGenome); // this part is optional, it changes some settings of the algorithm // for educational purposes, the default values are set here, just to // show how it can be done GeneticModel.ClearParentSelectionTypes(); GeneticModel.AddParentSelectionType(PARENTSELECTIONTYPE_RANK); GeneticModel.AddParentSelectionType(PARENTSELECTIONTYPE_RANK); GeneticModel.AddParentSelectionType(PARENTSELECTIONTYPE_RANK); GeneticModel.AddParentSelectionType(PARENTSELECTIONTYPE_RANK); GeneticModel.AddParentSelectionType(PARENTSELECTIONTYPE_TOURNAMENT); GeneticModel.ClearCrossoverTypes(); GeneticModel.AddCrossoverType(CROSSOVERTYPE_FIXEDLENGTH_ONEPOINT); GeneticModel.ClearMutationTypes(); GeneticModel.AddMutationType(MUTATIONTYPE_CHANGEGENE); GeneticModel.SetPopulationSize(100, 10, 10, -1); GeneticModel.SetMutationRate(1.0f); GeneticModel.Initialize(); // evolve the model until it found a fit enough genome GeneticModel.Evolve(); // print out the genome's value CGeneticGenome *FittestGenome = GeneticModel.GetFittestGenome(); printf("Genome %s\n", FittestGenome->ToString().GetBuffer()); } Links
|


| Top |
| #define | SOUP_STATUS_IS_TRANSPORT_ERROR() |
| #define | SOUP_STATUS_IS_INFORMATIONAL() |
| #define | SOUP_STATUS_IS_SUCCESSFUL() |
| #define | SOUP_STATUS_IS_REDIRECTION() |
| #define | SOUP_STATUS_IS_CLIENT_ERROR() |
| #define | SOUP_STATUS_IS_SERVER_ERROR() |
| const char * | soup_status_get_phrase () |
| guint | soup_status_proxify () |
#define SOUP_STATUS_IS_TRANSPORT_ERROR(status) ((status) > 0 && (status) < 100)
Tests if status
is a libsoup transport error.
#define SOUP_STATUS_IS_INFORMATIONAL(status) ((status) >= 100 && (status) < 200)
Tests if status
is an Informational (1xx) response.
#define SOUP_STATUS_IS_SUCCESSFUL(status) ((status) >= 200 && (status) < 300)
Tests if status
is a Successful (2xx) response.
#define SOUP_STATUS_IS_REDIRECTION(status) ((status) >= 300 && (status) < 400)
Tests if status
is a Redirection (3xx) response.
#define SOUP_STATUS_IS_CLIENT_ERROR(status) ((status) >= 400 && (status) < 500)
Tests if status
is a Client Error (4xx) response.
#define SOUP_STATUS_IS_SERVER_ERROR(status) ((status) >= 500 && (status) < 600)
Tests if status
is a Server Error (5xx) response.
const char *
soup_status_get_phrase (guint status_code
);
Looks up the stock HTTP description of status_code
. This is used
by soup_message_set_status()
to get the correct text to go with a
given status code.
There is no reason for you to ever use this function. If you wanted the textual description for the “status_code” of a given SoupMessage, you should just look at the message's “reason_phrase”. However, you should only do that for use in debugging messages; HTTP reason phrases are not localized, and are not generally very descriptive anyway, and so they should never be presented to the user directly. Instead, you should create you own error messages based on the status code, and on what you were trying to do.
guint
soup_status_proxify (guint status_code
);
Turns SOUP_STATUS_CANT_RESOLVE
into
SOUP_STATUS_CANT_RESOLVE_PROXY
and SOUP_STATUS_CANT_CONNECT
into
SOUP_STATUS_CANT_CONNECT_PROXY
. Other status codes are passed
through unchanged.
Since 2.26
These represent the known HTTP status code values, plus various network and internal errors.
Note that no libsoup functions take or return this type directly; any function that works with status codes will accept unrecognized status codes as well.
Prior to 2.44 this type was called
SoupKnownStatusCode
, but the individual values
have always had the names they have now.
|
No status available. (Eg, the message has not been sent yet) |
||
|
Message was cancelled locally |
||
|
Unable to resolve destination host name |
||
|
Unable to resolve proxy host name |
||
|
Unable to connect to remote host |
||
|
Unable to connect to proxy |
||
|
SSL/TLS negotiation failed |
||
|
A network error occurred, or the other end closed the connection unexpectedly |
||
|
Malformed data (usually a programmer error) |
||
|
Used internally |
||
|
There were too many redirections |
||
|
Used internally |
||
|
100 Continue (HTTP) |
||
|
101 Switching Protocols (HTTP) |
||
|
102 Processing (WebDAV) |
||
|
200 Success (HTTP). Also used by many lower-level soup routines to indicate success. |
||
|
201 Created (HTTP) |
||
|
202 Accepted (HTTP) |
||
|
203 Non-Authoritative Information (HTTP) |
||
|
204 No Content (HTTP) |
||
|
205 Reset Content (HTTP) |
||
|
206 Partial Content (HTTP) |
||
|
207 Multi-Status (WebDAV) |
||
|
300 Multiple Choices (HTTP) |
||
|
301 Moved Permanently (HTTP) |
||
|
302 Found (HTTP) |
||
|
302 Moved Temporarily (old name, RFC 2068) |
||
|
303 See Other (HTTP) |
||
|
304 Not Modified (HTTP) |
||
|
305 Use Proxy (HTTP) |
||
|
306 [Unused] (HTTP) |
||
|
307 Temporary Redirect (HTTP) |
||
|
400 Bad Request (HTTP) |
||
|
401 Unauthorized (HTTP) |
||
|
402 Payment Required (HTTP) |
||
|
403 Forbidden (HTTP) |
||
|
404 Not Found (HTTP) |
||
|
405 Method Not Allowed (HTTP) |
||
|
406 Not Acceptable (HTTP) |
||
|
407 Proxy Authentication Required (HTTP) |
||
|
shorter alias for
|
||
|
408 Request Timeout (HTTP) |
||
|
409 Conflict (HTTP) |
||
|
410 Gone (HTTP) |
||
|
411 Length Required (HTTP) |
||
|
412 Precondition Failed (HTTP) |
||
|
413 Request Entity Too Large (HTTP) |
||
|
414 Request-URI Too Long (HTTP) |
||
|
415 Unsupported Media Type (HTTP) |
||
|
416 Requested Range Not Satisfiable (HTTP) |
||
|
shorter alias for
|
||
|
417 Expectation Failed (HTTP) |
||
|
422 Unprocessable Entity (WebDAV) |
||
|
423 Locked (WebDAV) |
||
|
424 Failed Dependency (WebDAV) |
||
|
500 Internal Server Error (HTTP) |
||
|
501 Not Implemented (HTTP) |
||
|
502 Bad Gateway (HTTP) |
||
|
503 Service Unavailable (HTTP) |
||
|
504 Gateway Timeout (HTTP) |
||
|
505 HTTP Version Not Supported (HTTP) |
||
|
507 Insufficient Storage (WebDAV) |
||
|
510 Not Extended (RFC 2774) |
#define SOUP_HTTP_ERROR soup_http_error_quark()
A GError domain representing an HTTP status. Use a SoupStatus for
the code
value.


{{item.name || item.id }}
{{item.requiredCopayers}} of {{item.totalCopayers}} - {{networkName}}
, {{isComplete ? 'Complete' : 'Waiting for copayers...'}}
{{item.balanceInfo.totalBalance || 0}} {{item.settings.unitName}}
Approximate size: {{item.kb}} kB
({{item.usage}}%)
Copy backup in a safe place
Copy this text as it is in a safe place (notepad or email)


Vim documentation: recover
main help file*recover.txt* For Vim version 7.2. Last change: 2006 Apr 24 VIM REFERENCE MANUAL by Bram Moolenaar Recovery after a crash *crash-recovery* You have spent several hours typing in that text that has to be finished next morning, and then disaster strikes: Your computer crashes. DON'T PANIC! You can recover most of your changes from the files that Vim uses to store the contents of the file. Mostly you can recover your work with one command: vim -r filename 1. The swap file |swap-file| 2. Recovery |recovery|
1. The swap file *swap-file* Vim stores the things you changed in a swap file. Using the original file you started from plus the swap file you can mostly recover your work. You can see the name of the current swap file being used with the command: :sw[apname] *:sw* *:swapname* The name of the swap file is normally the same as the file you are editing, with the extension ".swp". - On Unix, a '.' is prepended to swap file names in the same directory as the edited file. This avoids that the swap file shows up in a directory listing. - On MS-DOS machines and when the 'shortname' option is on, any '.' in the original file name is replaced with '_'. - If this file already exists (e.g., when you are recovering from a crash) a warning is given and another extension is used, ".swo", ".swn", etc. - An existing file will never be overwritten. - The swap file is deleted as soon as Vim stops editing the file. Technical: The replacement of '.' with '_' is done to avoid problems with MS-DOS compatible filesystems (e.g., crossdos, multidos). If Vim is able to detect that the file is on an MS-DOS-like filesystem, a flag is set that has the same effect as the 'shortname' option. This flag is reset when you start editing another file. *E326* If the ".swp" file name already exists, the last character is decremented until there is no file with that name or ".saa" is reached. In the last case, no swap file is created. By setting the 'directory' option you can place the swap file in another place than where the edited file is. Advantages: - You will not pollute the directories with ".swp" files. - When the 'directory' is on another partition, reduce the risk of damaging the file system where the file is (in a crash). Disadvantages: - You can get name collisions from files with the same name but in different directories (although Vim tries to avoid that by comparing the path name). This will result in bogus ATTENTION warning messages. - When you use your home directory, and somebody else tries to edit the same file, he will not see your swap file and will not get the ATTENTION warning message. On the Amiga you can also use a recoverable ram disk, but there is no 100% guarantee that this works. Putting swap files in a normal ram disk (like RAM: on the Amiga) or in a place that is cleared when rebooting (like /tmp on Unix) makes no sense, you will lose the swap file in a crash. If you want to put swap files in a fixed place, put a command resembling the following ones in your .vimrc: :set dir=dh2:tmp (for Amiga) :set dir=~/tmp (for Unix) :set dir=c:\\tmp (for MS-DOS and Win32) This is also very handy when editing files on floppy. Of course you will have to create that "tmp" directory for this to work! For read-only files, a swap file is not used. Unless the file is big, causing the amount of memory used to be higher than given with 'maxmem' or 'maxmemtot'. And when making a change to a read-only file, the swap file is created anyway. The 'swapfile' option can be reset to avoid creating a swapfile. Detecting an existing swap file You can find this in the user manual, section |11.3|. Updating the swapfile The swap file is updated after typing 200 characters or when you have not typed anything for four seconds. This only happens if the buffer was changed, not when you only moved around. The reason why it is not kept up to date all the time is that this would slow down normal work too much. You can change the 200 character count with the 'updatecount' option. You can set the time with the 'updatetime' option. The time is given in milliseconds. After writing to the swap file Vim syncs the file to disk. This takes some time, especially on busy Unix systems. If you don't want this you can set the 'swapsync' option to an empty string. The risk of losing work becomes bigger though. On some non-Unix systems (MS-DOS, Amiga) the swap file won't be written at all. If the writing to the swap file is not wanted, it can be switched off by setting the 'updatecount' option to 0. The same is done when starting Vim with the "-n" option. Writing can be switched back on by setting the 'updatecount' option to non-zero. Swap files will be created for all buffers when doing this. But when setting 'updatecount' to zero, the existing swap files will not be removed, it will only affect files that will be opened after this. If you want to make sure that your changes are in the swap file use this command: *:pre* *:preserve* *E313* *E314* :pre[serve] Write all text for all buffers into swap file. The original file is no longer needed for recovery. This sets a flag in the current buffer. When the '&' flag is present in 'cpoptions' the swap file will not be deleted for this buffer when Vim exits and the buffer is still loaded |cpo-&|. {Vi: might also exit} A Vim swap file can be recognized by the first six characters: "b0VIM ". After that comes the version number, e.g., "3.0". Links and symbolic links On Unix it is possible to have two names for the same file. This can be done with hard links and with symbolic links (symlinks). For hard links Vim does not know the other name of the file. Therefore, the name of the swapfile will be based on the name you used to edit the file. There is no check for editing the same file by the other name too, because Vim cannot find the other swapfile (except for searching all of your harddisk, which would be very slow). For symbolic links Vim resolves the links to find the name of the actual file. The swap file name is based on that name. Thus it doesn't matter by what name you edit the file, the swap file name will normally be the same. However, there are exceptions: - When the directory of the actual file is not writable the swapfile is put elsewhere. - When the symbolic links somehow create a loop you get an *E773* error message and the unmodified file name will be used. You won't be able to save your file normally.
2. Recovery *recovery* *E308* *E311* Basic file recovery is explained in the user manual: |usr_11.txt|. Another way to do recovery is to start Vim and use the ":recover" command. This is easy when you start Vim to edit a file and you get the "ATTENTION: Found a swap file ..." message. In this case the single command ":recover" will do the work. You can also give the name of the file or the swap file to the recover command: *:rec* *:recover* *E305* *E306* *E307* :rec[over] [file] Try to recover [file] from the swap file. If [file] is not given use the file name for the current buffer. The current contents of the buffer are lost. This command fails if the buffer was modified. :rec[over]! [file] Like ":recover", but any changes in the current buffer are lost. *E312* *E309* *E310* Vim has some intelligence about what to do if the swap file is corrupt in some way. If Vim has doubt about what it found, it will give an error message and insert lines with "???" in the text. If you see an error message while recovering, search in the file for "???" to see what is wrong. You may want to cut and paste to get the text you need. The most common remark is "???LINES MISSING". This means that Vim cannot read the text from the original file. This can happen if the system crashed and parts of the original file were not written to disk. Be sure that the recovery was successful before overwriting the original file or deleting the swap file. It is good practice to write the recovered file elsewhere and run 'diff' to find out if the changes you want are in the recovered file. Once you are sure the recovery is ok delete the swap file. Otherwise, you will continue to get warning messages that the ".swp" file already exists. {Vi: recovers in another way and sends mail if there is something to recover} top - main help file


A StoryFrame defines the area of the map a viewer of your story will see. Set the default StoryFrame below, or create additional StoryFrames to override the part of the map your viewers will see for this chapter.
Please create a bounding box for your StoryFrame.
You have overlapping StoryFrames. Please adjust your dates:
{{ frameSvc.frameSettings[currentIndex].startDate | date: 'mediumDate' }} - {{ frameSvc.frameSettings[currentIndex].endDate | date: 'mediumDate'}}


Application provider is a role which provides the concrete console application instance in ACF, it provides the detailed information about console application, and determines the how the application behaves. It is easy to create application provider just by creating a new class which inherits from AdaptiveConsole.ConsoleApplicationBase, and implementing the abstract members.
Create a blank solution named catool in Visual Studio 2008
Create the Provider
|
public class CatoolApplication : ConsoleApplicationBase { } |
|
protected override string Description { get { return "A demonstration of" + "Adaptive Console Framework"; } }
protected override string Logo { get { return @"catool"; } } |
|
public CatoolApplication(string[] args) : base(args) { } |
|
using AdaptiveConsole;
namespace Catool.Provider { public class CatoolApplication : ConsoleApplicationBase { protected override string Description { get { return "A demonstration of " + "Adaptive Console Framework"; } }
protected override string Logo { get { return @"catool"; } }
public CatoolApplication(string[] args) : base(args) { } } } |
Now we have successfully defined the application provider. If you wish to customize the display of logo and body information of the help screen, you can protectly override the BannerTemplate and HelpBodyTemplate properties in your provider class. For more information about these two properties and templates, please refer to the Help Screen Customization chapter.


California Missing Persons - Redding.com
Redding Record Searchlight brings you the most current California Missing Persons news and information . 5314 · McKay, Dale L. 12/24/1978, Fountain Valley, CA, Male, White, 61 . 3881 · Root , Alma V. 1/1/1980, Auburn, CA, Female, White, 14 . 1448 · Smith JR, John W. 4/26/1996, Santa Cruz, CA, Male, White, 38 .
http://www.redding.com/databases/missing/california/
Treatment for Herniated or Bulging Discs
Music Lessons in Auburn | Guitar, Piano, Drums & Singing Teachers
TakeLessons offers private music lessons with prescreened, local teachers in Auburn, CA. Sign up for safe, affordable lessons in your area.
http://takelessons.com/auburn-ca-music-lessons
Big Bridge #12
. Company, Embarcadero Center SkyDeck Gallery, San Francisco, CA (with photographs by Larry Keenan & Dale Smith) . 2005 Narratives in Clay, V. Breier Gallery, San Francisco, CA . 1990 Auburn Arts 39, Auburn Arts Center, Auburn, CA .
http://www.bigbridge.org/artmcclure.htm
v dale smith auburn ca Herniated or Bulging Discs
Auburn Family Lawyers - Justia Lawyer Directory
Justia Lawyer Directory - Attorneys & CA Law Firms Auburn California - Lawyer, Legal Aid & Services Profiles Family Auburn.
http://lawyers.justia.com/lawyers/family-law/california/auburn
Placer County Genealogical Society - Auburn New Cemetery Index (S)
Auburn, California 95604. PCGS Logo. PCGS Cemetery Project volunteers doing data entry of the New Auburn Cemetery data from . BRUCE N/C-8-191-2 11/05 /1937 02/06/2008 02/25/2008 SMITH, DALE HENRY N/C-15-143-8 . LESTER W . N/C-8-244-7 06/28/1964 SMITH, MABEL V. N/C-8-110-7 10/13/1969 SMITH, .
http://pcgs.pcgenes.com/aubnc/aubnc-s.html
Sick of Obama endorsements | Auburn Journal
Aug 28, 2012 . Dale Smith, Auburn . Lant Barney · Top Commenter · Auburn, California . Dale Smith - a man most thoroughly disconnected from reality.
http://www.auburnjournal.com/article/sick-obama-endorsements
Official Impairment Listing for Spinal Disorders
King City Accident
Accident Reports in King City California, updated live from the news and police . The rider, 66-year-old Dale Smith of King City, was killed in the Thursday .
http://www.accidentin.com/california/king_city_accidents.htm
- sherburne pageant of bands (narrowing of the spine)
Distribution List / Draft EIR Timberline @ Auburn (PEIR T20080139)
Nov 10, 2010 . Auburn CA 95602. Dale Smith. Ad-hoc Committee to Save Our. North Auburn-- Quality of Life. 3410 Sunshine Way. Auburn CA 95602 .
http://www.placer.ca.gov/Departments/CommunityDevelopment/EnvCoordSvcs/EIR/Timberline/~/media/cdr/ECS/EIR/Timberline/FEIR/Appendix%20A.ashxAuburn Divorce Lawyers - Justia Lawyer Directory
Justia Lawyer Directory - Attorneys & CA Law Firms Auburn California - Lawyer, Legal Aid & Services Profiles Divorce Auburn.
http://lawyers.justia.com/lawyers/divorce/california/auburn
A message from Director Dale Smith - CalAware
Dec 2, 2011 . A message from Director Dale Smith . of guides already available on our website to help you navigate California's open government laws.
http://www.calaware.org/donation/message.php?id=46
California - La Sportiva
Arcadia, CA 91006 . AUBURN RUNNING COMPANY. 833 LINCOLN WAY AUBURN, CA 95603 . Belmont, CA 94002 . CANOGA PARK, CA 91303 .
http://www.sportiva.com/retailers/retailers/usa/california
Medical-Vocational Allowance for Herniated Disc
Smail to Smith, D - Interment.net
06/07/1995, US Army Air Corps, AVN 1, Res: Walnut Creek, CA, Plot: V 0 3779, bur. 06/09/1995. Smallwood . Smith, , b. 09/26/1947, d. 09/27/1947, Plot: E BLK464, bur. 10/01/1947, * Smith, , b. . Smith, Dale Raymond, b. 10/26/1917, d . . 01/10/1997, US Army, CAPT, Res: Auburn, CA, Plot: 2C 0 3832, bur. 01/31/ 1997 .
http://www.interment.net/data/us/ca/sanmateo/ggate/s/golden_s15.htm
Ikeda's California Country Market - Auburn, CA
350 Reviews of Ikeda's California Country Market "A five star hamburger stand! Ate there for the . Photo of Dale N. Elite '12; 1241 . It has been an Auburn institution since the early 1970s. Ikeda's offers: . Photo of Andee V. 104 friends . The crust was so flaky and buttery and there were *tons* of granny smith apples in it.
http://www.yelp.com/biz/ikedas-california-country-market-auburn?start=80
Appealing a Denial of Benefits
Sluder to Smith, D - Interment.net
12/11/1992, GYSGT USMC, Victorville; San Bernardino; Ca 92392, Plot: 13A 578 , bur . Slupski, Francis V, b. . Smerber, Dale Kirvin, b. . Smith, Auburn H, b.
http://www.interment.net/data/us/ca/riverside/rivnat/s/riverside_s15.htm
State-by-State Listing - National Association of Charter School ...
Auburn , CA 95603, Email, Michele Schuetz, N/A. Baldwin Park Unified . Helendale Elementary School District, LEA, 1, 15350 Riverview Road Helendale, CA 92342 . Morgan Hill, CA 95037, Email, Dr. Wesly Smith, N/A. Mountain Empire . 555 Franklin Street San Francisco, CA 94102, Email, Alan V. Broussard, Index .
http://www.qualitycharters.org/state-by-state-overviews-97


My wife and I play a game I call Anniversary Chicken where we see how long we can make it on the day of our anniversary before admitting what day it is. I’m still in the running but I may buckle soon… 😅
6/29/2021, 11:59:57 AM
Favs: 12
Retweets: 0
link


{% extends "layout.html" %} {% block title %}Run Simulation{% endblock %} {% block startover %}{% endblock %} {% block body %}
Enter the path to the directory where the simulation should be run. All input files will be copied there, and the output files will be written there.