<repo_name>Awaken3d/Connect4Updated<file_sep>/src/gameLogic.ts
//var h=6;//Rows
//var w=7;//Columns

//'use strict';
//angular.module('myApp',['ngTouch', 'ui.bootstrap', 'gameServices']).factory('gameLogic', function() {
module gameLogic {
  var h=6;//Rows
  var w=7;//Columns
export function isEqual(object1:any, object2:any) {
  //console.log(JSON.stringify(object1));
  //console.log(JSON.stringify(object2));

    return angular.equals(object1, object2);
  }

  export function copyObject(object:any) {
    return angular.copy(object);
  }

  /** Return the winner (either 'R' or 'B') or '' if there is no winner. */
  export function getWinner(board:any) {

    var count=0;


    function p(y:any, x:any) {
  return (y < 0 || x < 0 || y >= h || x >= w) ? 0 : board[y][x];
}
 //loops through rows, columns, diagonals, etc
  for (var y=0;y<h;y++){
    for(var x=0;x<w;x++){
 if(p(y,x)!==0 && p(y,x)!==''&& p(y,x)===p(y,x+1) && p(y,x)===p(y,x+2) && p(y,x)===p(y,x+3)){
 return p(y,x);
    }
   }
 }
  for (var y=0;y<h;y++){
    for(var x=0;x<w;x++){

    if(p(y,x)!==0 &&p(y,x)!==''&& p(y,x)===p(y+1,x) && p(y,x)===p(y+2,x) && p(y,x)===p(y+3,x)){
      return p(y,x);
    }
  }
}

  for (var y=0;y<h;y++){
    for(var x=0;x<w;x++){
      for(var d=-1;d<=1;d+=2){
if(p(y,x)!==0&&p(y,x)!==''&&  p(y,x)===p(y+1*d,x+1) && p(y,x)===p(y+2*d,x+2) && p(y,x)===p(y+3*d,x+3)) {

        return p(y,x);

    }
  }
}
}

  for (var y=0;y<h;y++){

  for(var x=0;x<w;x++){
  if(p(y,x)==='') {
  return '';
  }
  }
  }
}
export function isTie(board:any) {
    var i:any, j:any;
    for (i = 0; i < 5; i++) {
      for (j = 0; j < 6; j++) {
        if (board[i][j] === '') {
          // If there is an empty cell then we do not have a tie.
          return false;
        }
      }
    }
    // No empty cells --> tie!
    return true;
  }


  export function getInitialBoard(){

    return  [['', '', '','','','',''],
    ['', '', '','','','',''],
    ['', '', '','','','',''],
    ['', '', '','','','',''],
    ['', '', '','','','',''],
    ['', '', '','','','','']];
  }

  export function createComputerMove(board:any, turnIndexBeforeMove:any) {
      var possibleMoves:any = [];
      var i:any, j:any;
      for (i = 0; i < 6; i++) {
        for (j = 0; j <7 ; j++) {
          try {
            possibleMoves.push(createMove(board, i, j, turnIndexBeforeMove));
          } catch (e) {
            // The cell in that position was full.
          }
        }
      }
      var randomMove = possibleMoves[Math.floor(Math.random() * possibleMoves.length)];
      return randomMove;
  }













  export function createMove(board:any, row:any, col:any, turnIndexBeforeMove:any) {
    if (board === undefined) {
      // Initially (at the beginning of the match), the board in state is undefined.
      board = [['', '', '','','','',''],
       ['', '', '','','','',''],
       ['', '', '','','','',''],
       ['', '', '','','','',''],
       ['', '', '','','','',''],
       ['', '', '','','','','']];
    }
    if (board[row][col] !== '') {
      throw new Error("One can only make a move in an empty position!");
    }


    var count1=0;
    for(var i=5;i>=0;i--){
      if(board[i][col]===''){
        count1++;

      }

    }
      if(row!==count1-1){
      throw new Error("One can only make a move in an correct position!");;
      }




    var boardAfterMove = copyObject(board);
    boardAfterMove[row][col] = turnIndexBeforeMove === 0 ? 'R' : 'B';
    var winner = getWinner(boardAfterMove);
    var firstOperation:any;
    if (winner !== '' || isTie(board)) {
      // Game over.
      firstOperation = {endMatch: {endMatchScores:
      (winner === 'R' ? [1, 0] : (winner === 'B' ? [0, 1] : [0, 0]))}};
    } else {
      // Game continues. Now it's the opponent's turn (the turn switches from 0 to 1 and 1 to 0).
      firstOperation = {setTurn: {turnIndex: 1 - turnIndexBeforeMove}};
    }
    return [firstOperation,
            {set: {key: 'board', value: boardAfterMove}},
            {set: {key: 'delta', value: {row: row, col: col}}}];
  }


  /** Returns an array of {stateBeforeMove, move, comment}. */
  export function getExampleMoves(initialTurnIndex:any, initialState:any, arrayOfRowColComment:any) {
    var exampleMoves:any = [];
    var state = initialState;
    var turnIndex = initialTurnIndex;
    for (var i = 0; i < arrayOfRowColComment.length; i++) {
      var rowColComment = arrayOfRowColComment[i];
      var move = createMove(state.board, rowColComment.row, rowColComment.col, turnIndex);
      exampleMoves.push({
        stateBeforeMove: state,
        turnIndexBeforeMove: turnIndex,
        move: move,
        comment: {en: rowColComment.comment}});
      state = {board : move[1].set.value, delta: move[2].set.value};
      turnIndex = 1 - turnIndex;
    }
    return exampleMoves;
  }

  export function getRiddles() {
    return [
      getExampleMoves(0,
        {
          board:
              [['', '', '','','','',''],
               ['', '', '','','','',''],
               ['', '', 'B','','','',''],
               ['B', 'R', 'B','','','',''],
               ['B', 'B', 'R','','','',''],
               ['R', 'B', 'R','R','','','']],
          delta: {row: 3, col: 0}
        },
        [
        {row: 5, col: 3, comment: "Find the position for R where he could win in his next turn by having a diagonal "},
        {row: 2, col: 2, comment: "B played here"},
        {row: 2, col: 0, comment: "R wins by placing here having 4 diagonal elements ."}
      ]),
      getExampleMoves(1,
        {
          board:
              [['', '', '','','','',''],
               ['', '', '','','','',''],
               ['', '', 'B','','','',''],
               ['', 'R', 'B','','','',''],
               ['', 'R', 'B','','','',''],
               ['R', 'B', 'R','','','','']],
          delta: {row: 4, col: 1}
        },
        [
        {row: 2, col: 2, comment: "B places here to make a vertical 4"},
        {row: 3, col: 1, comment: "R places  to have 4 in a row in subsequent moves"},
        {row: 1, col: 2, comment: "B wins by having 4 in a row!"}
      ])
    ];
  }



  export function getExampleGame() {
    return getExampleMoves(0, {}, [
      {row: 5, col: 4 , comment: "The classic opening is to put R in the middle"},
      {row: 5, col: 3, comment: "Place B adjacent to R"},
      {row: 5, col: 5, comment: "Place R next to original R"},
      {row: 5, col: 2, comment: "Place B to adjacent to the first one"},
      {row: 4, col: 5, comment: "Place R on top of 1 R"},
      {row: 3, col: 3, comment: "Place R on top of yellow to prevent from reaching 4"},
      {row: 4, col: 2, comment: "Place B on top of another B."},
      {row: 3, col: 2, comment:"place R on top of that as well"},
      {row: 5, col: 1,comment:"Place B here to create a 4 next time"},
      {row: 5, col: 0,comment:"R blocks from B to create a 4"},
      {row: 4, col: 1,comment:"Place B here to create a 4 next time "},
      {row: 4, col: 0,comment:"R blocks this as well to prevent B to create a 4"},
      {row: 3, col: 1,comment:"Place B here to create a vertical 4 next time"},
      {row: 2, col: 1,comment:"R prevents it by placing R on top of B"},
      {row: 3, col: 5,comment:"Place B on top of R here"},
      {row: 4, col: 4,comment:"R places here"},
      {row: 5, col: 6,comment:"Place B here"},
      {row: 2, col: 1,comment:"R wins by creating a diagonal  "},

    ]);
  }









export function isMoveOk(params:any) {
    var move = params.move;
    var turnIndexBeforeMove = params.turnIndexBeforeMove;
    var stateBeforeMove = params.stateBeforeMove;

    try {
      // Example move:
      // [{setTurn: {turnIndex : 1},
      //  {set: {key: 'board', value: [['X', '', ''], ['', '', ''], ['', '', '']]}},
      //  {set: {key: 'delta', value: {row: 0, col: 0}}}]
      var deltaValue = move[2].set.value;
      var row = deltaValue.row;
      var col = deltaValue.col;
      var board = stateBeforeMove.board;
      if (board === undefined) {
        // Initially (at the beginning of the match), stateBeforeMove is {}.
        board = [['', '', '','','','',''],
        ['', '', '','','','',''],
        ['', '', '','','','',''],
        ['', '', '','','','',''],
        ['', '', '','','','',''],
        ['', '', '','','','','']];

      }
      // One can only make a move in an empty position
      if (board[row][col] !== '') {
        return false;
      }

        var count1=0;
        for(var i=5;i>=0;i--){
          if(board[i][col]===''){
            count1++;

          }

        }
          if(row!==count1-1){
            return false;
          }




      var expectedMove = createMove(board, row, col, turnIndexBeforeMove);
      if (!isEqual(move, expectedMove)) {
        return false;
      }
    } catch (e) {
      // if there are any exceptions then the move is illegal
      return false;
    }
    return true;
  }


 }





angular.module('myApp',['ngTouch', 'ui.bootstrap', 'gameServices']).factory('gameLogic', function() {
  return {
isMoveOk : gameLogic.isMoveOk,
getExampleGame : gameLogic.getExampleGame,
getRiddles : gameLogic.getRiddles,
getInitialBoard:gameLogic.getInitialBoard,
createMove :gameLogic.createMove,
createComputerMove :gameLogic.createComputerMove

  };
});
<file_sep>/src/game.ts

/*angular.module('myApp')
.controller('Ctrl', ['$scope','$rootScope', '$log', '$timeout',
        'gameLogic',  function (
   $scope:any, $rootScope:any, $log:any, $timeout:any,
   gameLogic:any) {*/
     module game{
    //'use strict';

        //resizeGameAreaService.setWidthToHeight(1.16667);
    let gameArea: HTMLElement;
    var rowsNum = 6;
    var colsNum = 7;
    //dragAndDropService.addDragListener("gameArea", handleDragEvent);
    var draggingLines:any;
     var horizontalDraggingLine:any;
     var verticalDraggingLine:any;
     //export var clickToDragPiece:HTMLElement = (<HTMLInputElement>document.getElementById("clickToDragPiece"));
     export var clickToDragPiece:HTMLElement;
     export function test(){
        console.log("clicktodrag" + clickToDragPiece);
        return "clicktodrag" + clickToDragPiece;
     }

    var canMakeMove = false;
    //added new variables
    var board:any = undefined;
    var isYourTurn:any;
    var turnIndex:number;
    var delta:any;
    export function init() {
      resizeGameAreaService.setWidthToHeight(1.16667);
      gameService.setGame({
        gameDeveloperEmail: "<EMAIL>",
        minNumberOfPlayers: 2,
        maxNumberOfPlayers: 2,
      //  exampleGame: gameLogic.exampleGame(),
        //riddles: gameLogic.riddles(),
        isMoveOk: gameLogic.isMoveOk,
        updateUI: updateUI
      });

      dragAndDropService.addDragListener("gameArea", handleDragEvent);
    }

    export function sendComputerMove(){
      gameService.makeMove(
        gameLogic.createComputerMove(board, turnIndex));
      }

      export function getIntegersTill(number:any) {
        var res:any = [];
        for (var i = 0; i < number; i++) {
          res.push(i);
        }
        return res;
      }

      export function updateUI(params:any) {
        // check if commented: $scope.jsonState = angular.toJson(params.stateAfterMove, true);
        board = params.stateAfterMove.board;
        delta = params.stateAfterMove.delta;
        if (board === undefined) {
          board = [
          ['', '', '', '', '', '', ''],
          ['', '', '', '', '', '', ''],
          ['', '', '', '', '', '', ''],
          ['', '', '', '', '', '', ''],
          ['', '', '', '', '', '', ''],
          ['', '', '', '', '', '', ''],

          ];
        }

         canMakeMove = params.turnIndexAfterMove >= 0 && // game is ongoing
        params.yourPlayerIndex === params.turnIndexAfterMove; // it's my turn


        isYourTurn = params.turnIndexAfterMove >= 0 && // game is ongoing
        params.yourPlayerIndex === params.turnIndexAfterMove; //it's my turn
        turnIndex = params.turnIndexAfterMove;
        // Is it the computer's turn?
        if (isYourTurn
          && params.playersInfo[params.yourPlayerIndex].playerId === '') {
            isYourTurn = false;
            $timeout(sendComputerMove, 1100);
          }
        }



        updateUI({stateAfterMove: {}, turnIndexAfterMove: 0, yourPlayerIndex: -2});

        export let cellClicked = function (row:any, col:any) {
          //$log.info(["Clicked on cell:", row, col]);
          if (!isYourTurn) {
            return;
          }

          try {
            var move = gameLogic.createMove(board, row, col, turnIndex);
            isYourTurn = false; // to prevent making another move

            gameService.makeMove(move);
          } catch (e) {
            //$log.info(["wrong move", row, col]);
            return;
          }
        };

        export let shouldSlowlyAppear = function (row:any, col:any) {
          return delta !== undefined
          && delta.row === row && delta.col === col;
        }
         export let shouldShowImage = function (row:any, col:any) {
      var cell = board[row][col];
      return cell !== "";
    };

        export let rows = getIntegersTill(rowsNum);
      export let cols = getIntegersTill(colsNum);
        export let isWhite = function (row:any, col:any) {
          if (board[row][col] === 'B')
          {
            return true;
          }
          else
          {
            return false;
          }
        }

        export let isBlack = function (row:any, col:any) {
          if (board[row][col] === 'R')
          {
            return true;
          }
          else
          {
            return false;
          }
        }

        export let oddSum = function (row:any, col:any){
          if ((row + col) % 2 !== 0)
          {
            return true;
          }
          else
          {
            return false;
          }
        }

        export let evenSum = function (row:any, col:any){
          if ((row + col) % 2 === 0)
          {
            return true;
          }
          else
          {
            return false;
          }
        }

        export let getImageSrc = function (row:any, col:any) {
      var cell = board[row][col];
      return cell === "R" ? "img/red.png"
          : cell === "B" ? "img/blue.png" : "";
        };

        export function handleDragEvent(type:any, clientX:any, clientY:any) {
      //if not your turn, dont handle event
      // if (!canMakeMove) {
      //   return;
      // }
      clickToDragPiece = document.getElementById("clickToDragPiece");
      gameArea = document.getElementById("gameArea");
      draggingLines = document.getElementById("draggingLines");
      horizontalDraggingLine = document.getElementById("horizontalDraggingLine");
      verticalDraggingLine = document.getElementById("verticalDraggingLine");
      // Center point in gameArea
      var x = clientX - gameArea.offsetLeft;
      var y = clientY - gameArea.offsetTop;
      // Is outside gameArea?
      if (x < 0 || y < 0 || x >= gameArea.clientWidth || y >= gameArea.clientHeight) {
        clickToDragPiece.style.display = "none";
        draggingLines.style.display = "none";
        return;
      }

      clickToDragPiece.style.display = "inline";
      draggingLines.style.display = "inline";

      // Inside gameArea. Let's find the containing square's row and col
      var col = Math.floor(colsNum * x / gameArea.clientWidth);
      var row = Math.floor(rowsNum * y / gameArea.clientHeight);

      var centerXY = getSquareCenterXY(row, col);
      verticalDraggingLine.setAttribute("x1", ""+centerXY.x);
      verticalDraggingLine.setAttribute("x2", ""+centerXY.x);
      horizontalDraggingLine.setAttribute("y1", ""+centerXY.y);
      horizontalDraggingLine.setAttribute("y2", ""+centerXY.y);
      var topLeft = getSquareTopLeft(row, col);
      clickToDragPiece.style.left = topLeft.left + "px";
      clickToDragPiece.style.top = topLeft.top + "px";

      if (type === "touchend" || type === "touchcancel" || type === "touchleave" || type === "mouseup") {
        // drag ended
        clickToDragPiece.style.display = "none";
        draggingLines.style.display = "none";
        dragDone(row, col);
      }
    }
    export function getSquareWidthHeight() {
      return {
        width: gameArea.clientWidth / colsNum,
        height: gameArea.clientHeight / rowsNum
      };
    }

    export function getSquareTopLeft(row:any, col:any) {
      var size = getSquareWidthHeight();
      return {top: row * size.height, left: col * size.width};
    }

    export function getSquareCenterXY(row:any, col:any) {
      var size = getSquareWidthHeight();
      return {
        x: col * size.width + size.width / 2,
        y: row * size.height + size.height / 2
      };
    }

  export function dragDone(row:any, col:any) {
      cellClicked(row, col);
      $rootScope.$apply(function () {
        //$log.info("Dragged to " + row + "x" + col);
      });
    }

    export let getPreviewSrc = function () {
      return  turnIndex === 1 ? "img/blue.png" : "img/red.png";
    };
}
    //window.handleDragEvent = handleDragEvent;
    angular.module('myApp')
    .run(function() {
      $rootScope['game'] = game;
        /*gameService.setGame({
          gameDeveloperEmail: "<EMAIL>",
          minNumberOfPlayers: 2,
          maxNumberOfPlayers: 2,
        //  exampleGame: gameLogic.exampleGame(),
          //riddles: gameLogic.riddles(),
          isMoveOk: gameLogic.isMoveOk,
          updateUI: updateUI
        });*/
        translate.setLanguage('en',{
        "RULES_OF_CONNECT4":"Rules of Connect4",
        "RULES_SLIDE1":"Each player drops a disc of their color down a column. The disc can fall only on the lowest available spot in the column",
        "RULES_SLIDE2":"The objective of the game is to connect four of one's own discs of the same color next to each other vertically, horizontally, or diagonally before your opponent",
        "CLOSE":"Close"
  });
  game.init();
});
<file_sep>/coverage/Chrome 46.0.2490 (Mac OS X 10.10.5)/src/aiService.js.html
<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for src/aiService.js</title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="../prettify.css">
    <link rel="stylesheet" href="../base.css">
    <style type='text/css'>
        div.coverage-summary .sorter {
            background-image: url(../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class="header high">
    <h1>Code coverage report for <span class="entity">src/aiService.js</span></h1>
    <h2>
        Statements: <span class="metric">89.36% <small>(42 / 47)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
        Branches: <span class="metric">80% <small>(8 / 10)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
        Functions: <span class="metric">66.67% <small>(2 / 3)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
        Lines: <span class="metric">89.36% <small>(42 / 47)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
        Ignored: <span class="metric"><span class="ignore-none">none</span></span> &nbsp;&nbsp;&nbsp;&nbsp;
    </h2>
    <div class="path"><a href="../index.html">All files</a> &#187; <a href="index.html">src/</a> &#187; aiService.js</div>
</div>
<div class="body">
<pre><table class="coverage">
<tr><td class="line-count">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73</td><td class="line-coverage"><span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">var aiService;
(function (aiService) {
    function createComputerMove(board, playerIndex) {
        console.log("ai has been summoned");
        <span class="missing-if-branch" title="if path not taken" >I</span>if (board === undefined) {
<span class="cstat-no" title="statement not covered" >            board = gameLogic.getInitialBoard();</span>
        }
        var pawn = 3;
        var positions;
        var result;
        if (playerIndex === 0) {
            var dogLocations = gameLogic.getDogPositions(board);
            pawn = Math.floor(Math.random() * 3);
            console.log(" dog selected to be moved " + (pawn));
            while (dogLocations[pawn].row === 1 &amp;&amp; dogLocations[pawn].col === 4) {
<span class="cstat-no" title="statement not covered" >                pawn = Math.floor(Math.random() * 3);</span>
            }
            console.log(" dog selected to be move after check " + (pawn));
            var dogRow = dogLocations[pawn].row;
            var dogCol = dogLocations[pawn].col;
            //setDogId(pawn+1);
            positions = gameLogic.legalMovesDog[dogRow][dogCol];
            //let m = positions[Math.floor(Math.random() * positions.length )];
            var m;
            while (result === undefined) {
                console.log("mpika");
                //while(m === undefined){
                m = positions[Math.floor(Math.random() * positions.length)];
                console.log(" move created by random " + m[0] + " " + m[1]);
                //}
                try {
                    result = gameLogic.createMove(board, { row: dogRow, col: dogCol }, { row: m[0], col: m[1] }, playerIndex);
                }
                catch (e) {
                }
                ;
                pawn = Math.floor(Math.random() * 3);
                //console.log(" dog selected to be moved "+ (pawn));
                while (dogLocations[pawn].row === 1 &amp;&amp; <span class="branch-1 cbranch-no" title="branch not covered" >dogLocations[pawn].col === 4)</span> {
<span class="cstat-no" title="statement not covered" >                    pawn = Math.floor(Math.random() * 3);</span>
                }
                dogRow = dogLocations[pawn].row;
                dogCol = dogLocations[pawn].col;
                //setDogId(pawn+1);
                positions = gameLogic.legalMovesDog[dogRow][dogCol];
            }
            return result;
        }
        else {
            var bunnyPosition = gameLogic.getBunnyPosition(board);
            positions = gameLogic.legalMovesBunny[bunnyPosition.row][bunnyPosition.col];
            var y;
            while (result === undefined) {
                y = positions[Math.floor(Math.random() * positions.length)];
                console.log(" move created by random " + y[0] + " " + y[1]);
                try {
                    result = gameLogic.createMove(board, { row: bunnyPosition.row, col: bunnyPosition.col }, { row: y[0], col: y[1] }, playerIndex);
                }
                catch (e) {
<span class="cstat-no" title="statement not covered" >                    console.log(e);</span>
                }
                ;
            }
            return result;
        }
    }
    aiService.createComputerMove = createComputerMove;
<span class="fstat-no" title="function not covered" >    function setDogId(id) {</span>
<span class="cstat-no" title="statement not covered" >        aiService.dogId = id;</span>
    }
    aiService.setDogId = setDogId;
})(aiService || (aiService = {}));
&nbsp;</pre></td></tr>
</table></pre>

</div>
<div class="footer">
    <div class="meta">Generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Nov 24 2015 11:25:14 GMT-0500 (EST)</div>
</div>
<script src="../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../sorter.js"></script>
</body>
</html>
