Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 1b6fab6

Browse files
author
Paul van Brenk
committed
Make the sample generic.
1 parent 9b2a6af commit 1b6fab6

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

mankala/Base.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
///<reference path="Driver.ts"/>
22

33
namespace Base {
4-
export interface IList {
4+
export interface IList<T> {
55
isHead: boolean;
6-
next: IList;
7-
prev: IList;
8-
insertAfter(entry: IList): IList;
9-
insertBefore(entry: IList): IList;
6+
next: IList<T>;
7+
prev: IList<T>;
8+
data: T;
9+
insertAfter(entry: IList<T>): IList<T>;
10+
insertBefore(entry: IList<T>): IList<T>;
1011
item();
1112
empty(): boolean;
1213
}
1314

14-
export class List implements IList {
15-
next: IList;
16-
prev: IList;
17-
18-
constructor (public isHead: boolean, public data) { }
15+
export class List<T> implements IList<T> {
16+
next: IList<T>;
17+
prev: IList<T>;
18+
19+
constructor(public isHead: boolean, public data: T) { }
1920

2021
item() {
2122
return this.data;
@@ -25,15 +26,15 @@ namespace Base {
2526
return this.next == this;
2627
}
2728

28-
insertAfter(entry: IList): IList {
29+
insertAfter(entry: IList<T>): IList<T> {
2930
entry.next = this.next;
3031
entry.prev = this;
3132
this.next = entry;
3233
entry.next.prev = entry;
3334
return (entry);
3435
}
3536

36-
insertBefore(entry: IList): IList {
37+
insertBefore(entry: IList<T>): IList<T> {
3738
this.prev.next = entry;
3839
entry.next = this;
3940
entry.prev = this.prev;
@@ -42,21 +43,21 @@ namespace Base {
4243
}
4344
}
4445

45-
export function listMakeEntry(data): IList {
46-
var entry: List = new List(false, data);
46+
export function listMakeEntry<T>(data: T): IList<T> {
47+
var entry: List<T> = new List<T>(false, data);
4748
entry.prev = entry;
4849
entry.next = entry;
4950
return entry;
5051
}
5152

52-
export function listMakeHead(): IList {
53-
var entry: List = new List(true, null);
53+
export function listMakeHead<T>(): IList<T> {
54+
var entry: List<T> = new List(true, null);
5455
entry.prev = entry;
5556
entry.next = entry;
5657
return entry;
5758
}
5859

59-
export function listRemove(entry: IList): IList {
60+
export function listRemove<T>(entry: IList<T>): IList<T> {
6061
if (entry == null) {
6162
return null;
6263
}

mankala/Game.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Mankala {
1414
const humanScoreId = "humanScore";
1515
const computerScoreId = "computerScore"
1616

17-
export interface IPositionList extends Base.IList {
17+
export interface IPositionList extends Base.IList<Position> {
1818
data: Position;
1919
push(pos: Position);
2020
pop(): Position;
@@ -25,7 +25,7 @@ namespace Mankala {
2525
}
2626

2727
function popPosition(l: IPositionList) {
28-
var entry: IPositionList = <IPositionList>Base.listRemove(l.next);
28+
var entry = Base.listRemove(l.next);
2929
if (entry != null) {
3030
return entry.data;
3131
} else {
@@ -165,7 +165,7 @@ namespace Mankala {
165165

166166
private findMove() {
167167
var timeStart = new Date().getTime();
168-
this.q = <IPositionList>Base.listMakeHead();
168+
this.q = <IPositionList>Base.listMakeHead<Position>();
169169
this.scores = [NoScore, NoScore, NoScore, NoScore, NoScore, NoScore];
170170
pushPosition(this.position, this.q);
171171
var deltaTime = 0;

0 commit comments

Comments
 (0)