Skip to content

Commit

Permalink
Criação dos modelos + inicio da lógica da criação dos brackets.
Browse files Browse the repository at this point in the history
  • Loading branch information
Renan Verissimo de vasconcelos committed Nov 13, 2018
1 parent 81a6e4e commit 30455be
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/bracketzada.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
import {assert} from 'chai';
describe('Array', function() {
describe('#indexOf()', function() {
it('should return -1 when the value is not present', function() {
assert.equal([1,2,3].indexOf(4), -1);
import {expect} from 'chai';
import {Tournament, Player} from './bracketzada.js';
describe('Teste do teste', function() {
describe('_generateGraph', function() {
it('Deve retornar um array com os nós conectados corretamente.', function() {
let players = [
new Player('a', 0),
new Player('a', 1),
new Player('a', 2),
new Player('a', 3),
new Player('a', 4),
new Player('a', 5),
new Player('a', 6),
new Player('a', 7),
new Player('a', 0),
new Player('a', 1),
new Player('a', 2),
new Player('a', 3),
new Player('a', 4),
new Player('a', 5),
new Player('a', 6),
new Player('a', 7),
]

let champ = new Tournament(players);
let graph = champ.generateBrackets();
//expect(graph[0].idParent).equals("Kappa");
});
});
});
85 changes: 85 additions & 0 deletions src/bracketzada.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
export class Player {
public id: number;
public name: string;

constructor(name: string, id: number) {
this.id = id;
this.name = name;
}
}

class Node {
public id: number;
public idChilden: any;
public playerLeft: any;
public playerRight: any;

constructor(id: number, idChilden?: Array<number>, playerLeft?: Player, playerRight?: Player) {
this.id = id;
this.idChilden = idChilden;
this.playerLeft = playerLeft;
this.playerRight = playerRight;
}

public addParent(ids: Array<number>) {
this.idChilden = ids;
}

public addPlayerLeft(player: Player) {
this.playerLeft = player;
}

public addPlayerRight(player: Player) {
this.playerRight = player;
}
}

class NodeWinner extends Node {
public playerWinner: any;

constructor(id: number, idChilden?: Array<number>, winner?: Player) {
super(id, idChilden);
this.playerWinner = winner;
}
}

export class Tournament {
public name: any;
public players: Array<Player>;

constructor(players: Array<Player>, name?: string) {
this.name = name || 'Bracketzada Tournament';
this.players = players;
}

private _numberNodes(numberPlayers: number) : number {
return Math.pow(2, Math.ceil(Math.log2(numberPlayers)));
}

private _generateGraph(numNodes: number) {
let graph = [];

//Winner Node
graph.push(new NodeWinner(0, [1]));

let actualParent = 1;
for (let i = 1; i < numNodes; i++) {
graph.push(
new Node(i, [actualParent, actualParent+1])
)
}

//this._setPlayers(graph, this.players);

}

private _setPlayers(graph: Array<Node>, players: Array<Player>) {

}

public generateBrackets() {
let numNodes = this._numberNodes(this.players.length);
let graph = this._generateGraph(numNodes);

}
}

0 comments on commit 30455be

Please sign in to comment.