index.js
/**
     * Handle mouse release in circle event - act only if target circle is next to initially clicked circle and line between them is hidden
     * 1. Check if user created cycle by his turn
     * 2. If yes, remove it and add earned points to user score
     * 3. Do computer move - pick the highest valued line
     * 4. Check if computer created cycle by his turn
     * 5. If yes, remove it and add earned points to computer score
     * @param {object} event
     */
Handle mouse release in circle event - act only if target circle is next to initially clicked circle and line between them is hidden
1. Check if user created cycle by his turn
2. If yes, remove it and add earned points to user score
3. Do computer move - pick the highest valued line
4. Check if computer created cycle by his turn
5. If yes, remove it and add earned points to computer score
@param {object} event
Handle mouse release in circle event - act only if target circle is next to initially clicked circle and line between them is hidden 1 . Check if user created cycle by his turn 2 . If yes remove it and add earned points to user score 3 . Do computer move - pick the highest valued line 4 . Check if computer created cycle by his turn 5 . If yes remove it and add earned points to computer score @param { object } event
function handleCircleUp(event){
        player = 1;
        let to = event.data.target;
        if(lines[Line.getLineId(from.id, to.id, CIRCLE_COUNT)].hidden && from.isNeighbour(to.id)) {
            circleContainer.off('mousemove', handleMove);
            circleContainer.off('mouseup', handleUp);
            for (let i = 0;  i < circles.length; i++) {
                circles[i].off('mouseup', handleCircleUp);
                circles[i].off('mouseover', handleCircleOver);
                circles[i].off('mouseout', handleCircleOut);
            }
            drawLine(from, to);
            findCycle();
            player = 2;
            let next = lines.map(function(line){
                if(line.hidden) {
                    return line.weight;
                } else {
                    return Number.MIN_SAFE_INTEGER;
                }
            }).reduce((max, maxValue, index, weights) => maxValue > weights[max] ? index : max, 0);
            drawLine(circles[lines[next].circles.from.id], circles[lines[next].circles.to.id], next);
            findCycle();
            resetFrom();
            to.animateScale(false);
        } else {
            handleUp();
        }
    }
function handleCircleUp ( event ) { player = 1 ; let to = event . data . target ; if ( lines [ Line . getLineId ( from . id , to . id , CIRCLE_COUNT ) ] . hidden && from . isNeighbour ( to . id ) ) { circleContainer . off ( 'mousemove' , handleMove ) ; circleContainer . off ( 'mouseup' , handleUp ) ; for ( let i = 0 ; i < circles . length ; i ++ ) { circles [ i ] . off ( 'mouseup' , handleCircleUp ) ; circles [ i ] . off ( 'mouseover' , handleCircleOver ) ; circles [ i ] . off ( 'mouseout' , handleCircleOut ) ; } drawLine ( from , to ) ; findCycle ( ) ; player = 2 ; let next = lines . map ( function ( line ) { if ( line . hidden ) { return line . weight ; } else { return Number . MIN_SAFE_INTEGER ; } } ) . reduce ( ( max , maxValue , index , weights ) => maxValue > weights [ max ] ? index : max , 0 ) ; drawLine ( circles [ lines [ next ] . circles . from . id ] , circles [ lines [ next ] . circles . to . id ] , next ) ; findCycle ( ) ; resetFrom ( ) ; to . animateScale ( false ) ; } else { handleUp ( ) ; } }
Handle mouse release in circle event - act only if target circle is next to initially clicked circle and line between them is hidden
 1.
Handle mouse release in circle event - act only if target circle is next to initially clicked circle and line between them is hidden 1 .
// This move made user // This move is going to make computer // AI pick line with the highest weight -> create array of weights and find index of the highest value // Check only hidden lines