当前位置: 首页>>代码示例>>Golang>>正文


Golang Vector.Last方法代码示例

本文整理汇总了Golang中container/vector.Vector.Last方法的典型用法代码示例。如果您正苦于以下问题:Golang Vector.Last方法的具体用法?Golang Vector.Last怎么用?Golang Vector.Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在container/vector.Vector的用法示例。


在下文中一共展示了Vector.Last方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: PutAt

// PutAt will put a give piece at the given position and return removed pieces and the response code.
func (b *Board) PutAt(c cell.Cell, x int, y int, h *history.History) (vector.Vector, PutResponse) {
	if b.At(x, y) != cell.SPACE {
		return nil, OCCUPIED
	}

	b.putAt(c, x, y)
	takenOffs := vector.Vector{}
	rc := c.Reverse()
	if b.shouldTakeOff(x-1, y, rc) {
		b.takeOff(x-1, y, rc, &takenOffs)
	}
	if b.shouldTakeOff(x+1, y, rc) {
		b.takeOff(x+1, y, rc, &takenOffs)
	}
	if b.shouldTakeOff(x, y-1, rc) {
		b.takeOff(x, y-1, rc, &takenOffs)
	}
	if b.shouldTakeOff(x, y+1, rc) {
		b.takeOff(x, y+1, rc, &takenOffs)
	}

	if b.shouldTakeOff(x, y, c) {
		b.TakeAt(x, y)
		return nil, FORBIDDEN
	}

	if len(takenOffs) == 1 && h.IsKo(c, x, y) {
		b.putAt(cell.SPACE, x, y)
		taken := takenOffs.Last().(point.Point)
		b.putAt(c.Reverse(), taken.X(), taken.Y())
		return nil, KO
	}

	return takenOffs, OK
}
开发者ID:Kazuya-Muramatsu,项目名称:Go-Go,代码行数:36,代码来源:board.go

示例2: ParseExpression

func (lex *Lexer) ParseExpression() *vector.Vector {
	tree := new(vector.Vector)
	for lex.current != "" {
		if lex.current == "," {
			break
		} else if lex.current == "(" {
			lex.Consume()
			args := lex.ParseArguments()
			if lex.current == ")" {
				if tree.Len() == 0 {
					tree.Push(NewMessage("", new(vector.Vector)))
				}

				if tree.Last().(IMessage).GetArguments().Len() > 0 {
					println("*** Arguments are empty")
					tree.Push(NewMessage("", new(vector.Vector)))
				}

				tree.Last().(IMessage).SetArguments(args)
			} else {
				println("Syntax Error: ')' expected")
			}
			println(len(*args))
		} else if lex.current == ")" {
			break
		} else {
			println("*** (ParseExpression) / fallback (line: " + strconv.Itoa(lex.line) + ") -- lex.current = " + lex.current + "; lex.next = " + lex.next)
			tree.Push(NewMessage(lex.current, new(vector.Vector)))
			lex.Consume()
		}
	}

	return tree
}
开发者ID:saysjonathan,项目名称:europa,代码行数:34,代码来源:parser.go

示例3: ConvertGridToString

func ConvertGridToString(grid *vector.Vector) string {
	var output, format string

	for _, lineInterface := range *grid {
		line := lineInterface.(*vector.IntVector)
		for j, number := range *line {
			format = "%d"
			if j+1 != line.Len() {
				format += " "
			}

			output += fmt.Sprintf(format, number)
		}

		if lineInterface != grid.Last() {
			output += "\n"
		}
	}

	return output
}
开发者ID:andrewsmedina,项目名称:euler,代码行数:21,代码来源:11.go

示例4: parse_forth

func parse_forth(dat string, DataStack *vector.Vector) {
	L := DataStack.Len()

	switch strings.TrimSpace(string(dat)) {
	case "":
	case "<cr>":
		return
	case "t":
		//check the DataStack size using the popped value
		//	if it passes, then the program continues
		minimum := int(DataStack.Pop().(float32))
		if DataStack.Len() < minimum {
			log.Println("DataStack has not enough minerals (values)")
		}
	case ".":
		log.Println(DataStack.Pop())
	case "0SP":
		DataStack.Cut(0, L)
	case ".S":
		log.Println(DataStack)
	case "2/":
		DataStack.Push(DataStack.Pop().(float32) / 2)
	case "2*":
		DataStack.Push(DataStack.Pop().(float32) * 2)
	case "2-":
		DataStack.Push(DataStack.Pop().(float32) - 2)
	case "2+":
		DataStack.Push(DataStack.Pop().(float32) + 2)
	case "1-":
		DataStack.Push(DataStack.Pop().(float32) - 1)
	case "1+":
		DataStack.Push(DataStack.Pop().(float32) + 1)
	case "DUP":
		DataStack.Push(DataStack.Last())
	case "?DUP":
		if DataStack.Last().(float32) != 0 {
			DataStack.Push(DataStack.Last().(float32))
		}
	case "PICK":
		number := int(DataStack.Pop().(float32))

		if number < L {
			DataStack.Push(DataStack.At(L - 1 - number).(float32))
		} else {
			log.Fatal("picking out of stack not allowed. Stack Length: " + string(L) + ". Selecting: " + string(number) + ".")
			return
		}
	case "TUCK":
		DataStack.Insert(L-2, int(DataStack.Last().(float32)))
	case "NIP":
		DataStack.Delete(L - 2)
	case "2DROP":
		DataStack.Pop()
		DataStack.Pop()
	case "2DUP":
		DataStack.Push(DataStack.At(L - 2))
		DataStack.Push(DataStack.At(DataStack.Len() - 2))
	case "DROP":
		DataStack.Pop()
	case "OVER":
		DataStack.Push(DataStack.At(L - 2))
	case "SWAP":
		l := DataStack.Len()
		DataStack.Swap(l-2, l-1)
	case "*":
		num1 := DataStack.Pop().(float32)
		num2 := DataStack.Pop().(float32)
		DataStack.Push(num1 * num2)
	case "+":
		num1 := DataStack.Pop().(float32)
		num2 := DataStack.Pop().(float32)
		DataStack.Push(num1 + num2)
	case "-":
		num1 := DataStack.Pop().(float32)
		num2 := DataStack.Pop().(float32)
		DataStack.Push(num2 - num1)
	case "/":
		num1 := DataStack.Pop().(float32)
		num2 := DataStack.Pop().(float32)
		DataStack.Push(num2 / num1)
	case "-ROT":
		DataStack.Swap(L-1, L-2)
		DataStack.Swap(L-2, L-3)
	case "ROT":
		DataStack.Swap(L-3, L-2)
		DataStack.Swap(L-2, L-1)
	case "2OVER":
		DataStack.Push(DataStack.At(L - 4))
		DataStack.Push(DataStack.At(DataStack.Len() - 4))
	case "2SWAP":
		DataStack.Swap(L-4, L-2)
		DataStack.Swap(L-3, L-1)
	case "EMIT":
		log.Println(string([]byte{uint8(DataStack.Last().(float32))}))
	default:
		val, ok := strconv.Atof32(dat)

		if ok == nil {
			DataStack.Push(val)
		} else {
//.........这里部分代码省略.........
开发者ID:nunb,项目名称:GoForth,代码行数:101,代码来源:main.go

示例5: Overlay


//.........这里部分代码省略.........
			if e.end.Point.Equal(evt.point) {
				R.Push(e)
				T.segments.Delete(i)
			} else if e.Line().On(evt.point) {
				return nil, os.NewError("intersection not at an endpoint")
			} else {
				i++
			}
		}

		// Fill in handle event. You won't need the whole damn thing because
		// Most of the time you just abort with non-terminal intersection
		T.sweepLocation = evt.point
		sort.Sort(T)
		//fmt.Fprintf(os.Stderr,"status: %v\n",T.segments)
		if L.Len() == 0 && R.Len() == 0 {
			return nil, os.NewError("event point with no edges terminal at it " + evt.point.String() + fmt.Sprintf("current status: %v", T.segments))
		} else if L.Len() == 0 {
			above := sort.Search(T.Len(), func(i int) bool {
				return T.segments.At(i).(*Edge).Line().Below(evt.point)
			})
			//fmt.Fprintf(os.Stderr,"Testing status point, no new edge. above: %v, Len: %v\n",above,T.Len())
			if 0 < above && above < T.Len() {
				sa := T.segments.At(above).(*Edge)
				sb := T.segments.At(above - 1).(*Edge)

				cross, _, _ := sb.Line().IntersectAsFloats(sa.Line())
				if cross && !sa.Coterminal(sb) {
					return nil, os.NewError("intersection not at an endpoint")
				}
			}
		} else {
			aboveL := sort.Search(T.Len(), func(i int) bool {
				return L.Last().(*Edge).Line().LessAt(T.segments.At(i).(*Edge).Line(), evt.point)
			})
			belowL := aboveL - 1
			//fmt.Fprintf(os.Stderr,"Testing status point, new edges. above: %v, Len: %v\n",aboveL,T.Len())
			if 0 <= belowL && belowL < T.Len() {
				sa := L.At(0).(*Edge)
				sb := T.segments.At(belowL).(*Edge)

				cross, _, _ := sa.Line().IntersectAsFloats(sb.Line())
				if cross && !sa.Coterminal(sb) {
					return nil, os.NewError("intersection not at an endpoint")
				}
			}
			if aboveL < T.Len() {
				sa := T.segments.At(aboveL).(*Edge)
				sb := L.Last().(*Edge)

				cross, _, _ := sa.Line().IntersectAsFloats(sb.Line())
				if cross && !sa.Coterminal(sb) {
					return nil, os.NewError("intersection not at an endpoint")
				}
			}
		}

		// This is the barrier between preparing the new vertex (below) and determining if the new vertex is good 

		// Setting up edges
		nv := NewVertex(evt.point.Copy())
		R.Do(func(r interface{}) {
			nv.OutgoingEdges.Push(r.(*Edge).twin)
			r.(*Edge).end = nv
			r.(*Edge).twin.start = nv
			o.Edges.Push(r)
开发者ID:ebering,项目名称:zellij,代码行数:67,代码来源:overlay.go


注:本文中的container/vector.Vector.Last方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。