def buildsquares(self):
     self.container.x()
     self.sqdivs = {}
     self.sqhdivs = {}
     for sq in self.squarelist():
         sqclass = cpick(self.islightsquare(sq), "boardsquarelight", "boardsquaredark")
         sqdiv = Div().ac(["boardsquare", sqclass]).w(self.squaresize).h(self.squaresize)
         sqhdiv = Div().pa().w(self.squaresize).h(self.squaresize)
         self.sqdivs[sq.hashkey()] = sqdiv
         self.sqhdivs[sq.hashkey()] = {
             "div": sqhdiv,
             "cumop": 0.0
         }
         fasq = self.flipawaresquare(sq)
         sqdiv.pv(self.squarecoordsvect(fasq))
         sqhdiv.pv(self.squarecoordsvect(fasq))
         sqdiv.ae("dragover", self.piecedragoverfactory(sq))
         sqdiv.ae("drop", self.piecedropfactory(sq))            
         sqhdiv.ae("dragover", self.piecedragoverfactory(sq))
         sqhdiv.ae("drop", self.piecedropfactory(sq))            
         self.container.a([sqdiv, sqhdiv])
         p = self.getpieceatsquare(sq)
         if p.ispiece():
             pdiv = Div().ac("boardpiece").w(self.piecesize).h(self.piecesize).pv(self.piececoordsvect(fasq))
             pdiv.ac(getclassforpiece(p, self.piecestyle)).sa("draggable", True)
             pdiv.ae("dragstart", self.piecedragstartfactory(sq, pdiv))
             pdiv.ae("drag", self.piecedragfactory())
             pdiv.ae("dragend", self.piecedragendfactory(sq, pdiv))
             pdiv.ae("dragover", self.piecedragoverfactory(sq))
             pdiv.ae("drop", self.piecedropfactory(sq))            
             pdiv.zi(10)
             if self.variantkey == "threeCheck":
                 if ( p.kind == "k" ):
                     mul = self.getthreelifesforcolor(p.color)
                     lifesdiv = Div().pa().t(- self.squaresize / 10).l(self.squaresize / 2 + self.squaresize / 10).w(self.squaresize / 2).h(self.squaresize / 2)
                     lifesdiv.ac("boardthreechecklifesdiv").fs(self.squaresize / 1.5).html("{}".format(mul))
                     lifesdiv.c(["#ff0", "#ff0"][p.color])
                     pdiv.a(lifesdiv)
             self.container.a(pdiv)
class MultipvInfo(e):
    def bestmovesanclickedfactory(self, moveuci, dostore = False):
        def bestmovesanclicked():
            if not ( self.bestmovesanclickedcallback is None ):
                self.bestmovesanclickedcallback(moveuci, dostore)
        return bestmovesanclicked

    def scorebonus(self):
        if "scorebonus" in self.infoi:
            try:
                scorebonus = int(self.infoi["scorebonus"])
                return scorebonus
            except:
                pass
        return 0

    def effscore(self):
        return self.scorenumerical + self.scorebonus()

    def bonussliderchanged(self):
        self.infoi["scorebonus"] = self.bonusslider.v()
        self.build()            
        if not ( self.bonussliderchangedcallback is None ):            
            self.bonussliderchangedcallback()

    def traincombochanged(self):
        self.infoi["metrainweight"] = self.metraincombo.v()
        self.infoi["opptrainweight"] = self.opptraincombo.v()
        self.build()

    def build(self, gamesan = None):            
        self.bestmoveuci = self.infoi["bestmoveuci"]
        self.bestmovesan = self.infoi["bestmovesan"]
        self.scorenumerical = self.infoi["scorenumerical"]
        self.pvsan = self.infoi["pvsan"]
        self.pvsans = self.pvsan.split(" ")
        if len(self.pvsans) > ( self.pvlength + 1 ):
            self.pvsans = self.pvsans[0:self.pvlength + 1]
        if len(self.pvsans) > 1:
            self.pvsans = self.pvsans[1:]
        self.showpv = " ".join(self.pvsans)
        self.pvpgn = self.infoi["pvpgn"]
        self.depth = self.infoi["depth"]
        self.nps = self.infoi["nps"]        
        self.container = Div().ac("multipvinfocontainer")
        self.idiv = Div().ac("multipvinfoi").html("{}.".format(self.i))
        self.bestmovesandiv = Div().ac("multipvinfobestmovesan").html(self.bestmovesan)
        if gamesan == self.bestmovesan:
            self.bestmovesandiv.bc("#fbf")
        self.bestmovesandiv.ae("mousedown", self.bestmovesanclickedfactory(self.bestmoveuci))        
        self.scorenumericaldiv = Div().ac("multipvinfoscorenumerical").html("{}".format(scoreverbal(self.effscore()))).cp()
        self.scorenumericaldiv.ae("mousedown", self.bestmovesanclickedfactory(self.bestmoveuci, True))        
        self.bonussliderdiv = Div().ac("multipvinfobonussliderdiv")
        self.bonusslider = Slider().setmin(-500).setmax(500).ac("multipvinfobonusslider").sv(self.scorebonus())        
        self.bonusslider.ae("change", self.bonussliderchanged)
        self.bonussliderdiv.a(self.bonusslider)
        self.depthdiv = Div().ac("multipvinfodepth").html("{}".format(self.depth))
        self.miscdiv = Div().ac("multipvinfomisc").html("nps {}".format(self.nps))
        self.traindiv = Div().ac("multipvinfomisc").w(100)        
        metrainweight = self.infoi["metrainweight"]        
        hasmetrain = False
        if not metrainweight:
            metrainweight = "0"            
        opptrainweight = self.infoi["opptrainweight"]
        hasopptrain = False
        if not opptrainweight:
            opptrainweight = "0"                
        try:
            if int(metrainweight) > 0:
                hasmetrain = True
            if int(opptrainweight) > 0:
                hasopptrain = True
        except:
            pass
        if hasmetrain and hasopptrain:
            self.trainbc = "#00f"
        elif hasmetrain:
            self.trainbc = "#0f0"
        elif hasopptrain:
            self.trainbc = "#f00"
        else:
            self.trainbc = "inherit"                
        self.metrainweight = int(metrainweight)
        self.opptrainweight = int(opptrainweight)
        self.avgtrainweight = ( self.metrainweight + self.opptrainweight ) / 2.0
        self.trainop = self.avgtrainweight / 10.0
        self.metraincombo = ComboBox().setoptions(TRAIN_OPTIONS, metrainweight, self.traincombochanged)
        self.opptraincombo = ComboBox().setoptions(TRAIN_OPTIONS, opptrainweight, self.traincombochanged)        
        self.traindiv.a([self.metraincombo, self.opptraincombo])        
        self.pvdiv = Div().ac("multipvinfopv").html(self.showpv).c("#070").fw("bold")
        self.container.a([self.idiv, self.bestmovesandiv, self.scorenumericaldiv, self.bonussliderdiv, self.traindiv, self.depthdiv, self.pvdiv])        
        self.container.bc(self.trainbc)
        self.bestmovesandiv.c(scorecolor(self.effscore()))
        self.scorenumericaldiv.c(scorecolor(self.effscore()))        
        self.x().a(self.container)        

    def __init__(self, infoi, pvlength = 4):
        super().__init__("div")
        self.pvlength = pvlength
        self.bestmovesanclickedcallback = None
        self.bonussliderchangedcallback = None
        self.infoi = infoi
        self.i = self.infoi["i"]
        self.build()